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'

bugouserbugouser Posts: 5Questions: 1Answers: 0

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

Answers

  • bugouserbugouser Posts: 5Questions: 1Answers: 0

    lol, i did it.

    1. modify two "moment" function calls in datetime-moment.js - remove 4th param:

      moment( d.replace ? d.replace(/<.*?>/g, '') : d, format, locale )

    2. init like this: $.fn.dataTable.moment( 'DD.MM.YYYY (HH:mm)' );

  • allanallan Posts: 64,032Questions: 1Answers: 10,555 Site admin

    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

  • bugouserbugouser Posts: 5Questions: 1Answers: 0

    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)?

  • allanallan Posts: 64,032Questions: 1Answers: 10,555 Site admin

    Are you able to link to a test page showing the issue so I can debug it?

    Allan

  • bugouserbugouser Posts: 5Questions: 1Answers: 0
  • allanallan Posts: 64,032Questions: 1Answers: 10,555 Site admin
    Answer ✓

    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

  • bugouserbugouser Posts: 5Questions: 1Answers: 0

    Thx for help

This discussion has been closed.