Sorting in column containing dates in 'DD.MM.YYYY' or 'DD.MM.YYYY HH:mm'
Sorting in column containing dates in 'DD.MM.YYYY' or 'DD.MM.YYYY HH:mm'

Hi, i have a column, containing dates in 2 different formats, some has dates only, some has date and time values
Example of data:
29.07.2015 08:45
04.08.2015 10:00
14.08.2015
i use "ultimate date / time sorting plugin" and init 2 formats:
$.fn.dataTable.moment( 'DD.MM.YYYY' );
$.fn.dataTable.moment( 'DD.MM.YYYY HH:mm' );
but sorting not working. Why?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
lol, i did it.
modify two "moment" function calls in datetime-moment.js - remove 4th param:
moment( d.replace ? d.replace(/<.*?>/g, '') : d, format, locale )
init like this: $.fn.dataTable.moment( 'DD.MM.YYYY (HH:mm)' );
The fourth parameter make the moment parsing strict. That suggests that the format given does not exactly match the data. Possibly due to white space?
Allan
Thx, for help, i understood that "strict mode off" helped me.
But still dont know, why sort date and datetime in one column does not work (in strict mode)?
Are you able to link to a test page showing the issue so I can debug it?
Allan
live datables case http://live.datatables.net/kidixede/1/
Super - thanks. So the issue here is that there are two different date formats in your
date
column. Some have a time, some don't. A column can only have one sorting type, thus why it doesn't work.Looking through the Moment.js documentation I don't see any way to provide optional parts of a format. That would be quite useful - for example:
DD.MM.YYYY( HH:mm)?
- but that isn't possible at this time.So yes, strict formatting would need to be disabled for this case where formats have been mixed.
Allan
Thx for help