Datetime-moment sorting not working
Datetime-moment sorting not working
Hi,
I'm trying to sort some columns with the datetime-sorting plugin.
This is the relevant code:
$.fn.dataTable.moment('DD.MM.YYYY');
dataTable = $('#table-inventar').DataTable({
ajax: {
url: '/' + table + '/json',
dataSrc: ''
},
columns: columns,
language: {
url: '//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/German.json'
},
responsive: true
});
It does not sort the relevant columns correctly (no change to before the integration of the plugin).
I tried debugging the plugin.The types.detect.unshift
part seems to work correctly. moment( d, format, locale, true ).isValid()
becomes true
where expected. However, when sorting the relevant column, the types.order[ 'moment-'+format+'-pre' ]
part is never called, which i suppose it should? What am I doing wrong?
Im using jQuery 3.1.1, dataTables 1.10.16, moment.js 2.22.1 and the current version of the datetime-moment plugin.
This question has accepted answers - jump to:
Answers
That looks fine. Do you have rows in the table that do not contain a valid date? If it is likely not to work. This post has a couple of valuable hints:
https://datatables.net/forums/discussion/49621
We'd really need a link to a page showing the issue. The error suggests that one or more data points in the column don't match the date format given.
Allan
There was indeed an invalid date in the data. The item didn't show up in the table at all, so I didn't notice before. Thank you for your help!
Maybe relevant for you @jwa or somebody else. I just had to modify the date time plug in to also handle non date values. This is what I did to include a row with totals into one of my tables. By returning a high date in case the totals row is hit I make sure the totals stay at the bottom when ordering ascending and vice versa.
Try this,
// "sType": "date" TO SPECIFY SORTING IS APPLICABLE ON DATE
"aoColumns": [
null,
null,
null,
null,
{"sType": "date"},
null
]