Unable to use multiple date formats for moment due to format naming function
Unable to use multiple date formats for moment due to format naming function
Link to test case:
https://live.datatables.net/culafofa/1/
Error messages shown:
Uncaught TypeError: t.replace is not a function
De https://localhost/lib/datatables/2.0.5/datatables.min.js:41
datetime https://localhost/lib/datatables/2.0.5/datatables.min.js:41
<anonymous> https://localhost/js/utilities/datatables/2.0/defaults.js?v=:92
Uncaught TypeError: name.replace is not a function
__mldFnName https://localhost/lib/datatables/2.0.5/datatables.js:97264
datetime https://localhost/lib/datatables/2.0.5/datatables.js:97442
<anonymous> https://localhost/js/utilities/datatables/2.0/defaults.js?v=:92
Description of problem:
Can't use multiple formats with moment, due to it attempting to set a name up for the format that expects a string, where moment can accept an array
Potential fix
function __mldFnName(name) {
if (Array.isArray(name)) {
return name[0].replace(/[\W]/g, '')
}
return name.replace(/[\W]/g, '')
}
This question has an accepted answers - jump to answer
Answers
The test case doesn't show those errors.
You have the wrong format defined for the End Date:
05/7/2012
. You haveDD/MM/YYYY
but it should beDD/M/YYYY
with oneM
instead of two. See the Moment format docs.The
DataTable.datetime()
specifies it takes a string for the format not an array. Although the array seems to work with the updated format:Updated example:
https://live.datatables.net/culafofa/2/edit
It might be better to follow the docs and supply a string by using
DataTable.datetime()
multiple times, for example:Example:
https://live.datatables.net/kavecejo/1/edit
Kevin
That's odd could of sworn it wasn't working in the wasn't working Guess I need to pay more attention to my own example, must have been fixed since 2.0.5 which is the version I was getting the issue on
Ooh I see why my example wasn't working, I had an extra M in the format, so it didn't accept one letter months.
Figured the lack of an error was something else
I changed how the naming is done for 2.1. There was potential for overlap based on the non-formatting characters as you say.
Allan