how do you solve "Uncaught TypeError: $.fn.dataTable.moment is not a function" exception?
how do you solve "Uncaught TypeError: $.fn.dataTable.moment is not a function" exception?
When loading a datatable into a dialog I process initialisation files and scripts using $.getScript(url) and $.globalEval(script).
However, when I add the moment.js code I get the error "Uncaught TypeError: $.fn.dataTable.moment is not a function".
The script is
$.getScript("//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js");
$.getScript("//cdn.datatables.net/plug-ins/1.10.12/sorting/datetime-moment.js");
$.getScript("//cdn.datatables.net/v/bs/dt-1.10.12/b-1.2.2/fc-3.2.2/fh-3.1.2/r-2.1.0/se-1.2.0/datatables.min.js");
$.globalEval(aScript);
aScript is
$.fn.dataTable.moment("DD-MM-YYYY HH:mm");
$("#filelist").DataTable(
{
//various settings
});
If I change the loading order of the files
$.getScript("//cdn.datatables.net/v/bs/dt-1.10.12/b-1.2.2/fc-3.2.2/fh-3.1.2/r-2.1.0/se-1.2.0/datatables.min.js");
$.getScript("//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js");
$.getScript("//cdn.datatables.net/plug-ins/1.10.12/sorting/datetime-moment.js");
$.globalEval(aScript);
I get 2 errors
Uncaught ReferenceError: moment is not defined
and then
Uncaught TypeError: Cannot read property 'moment' of undefined
If I load all the files to the page and call $.fn.dataTable.moment("DD-MM-YYYY HH:mm") in the document load (although at that stage I don't know if I'll need them at that point) it all works.
Any ideas?
Thanks
Answers
Try loading in the following order:
If that doesn't work, we'd need a link to the page showing the issue.
Allan
I haven't had a chance to test this. Adding the code and files to the page before any Ajax call to create a dialog works, so I'll put this on the back burner at the moment. Thanks.