Datatables Sorting: datetime-moment doesn't work with 'DD.MM.YYYY', but with 'MM.DD.YYYY'?

Datatables Sorting: datetime-moment doesn't work with 'DD.MM.YYYY', but with 'MM.DD.YYYY'?

cmrtncmrtn Posts: 4Questions: 1Answers: 0

I am using Datatables do display a huge amount of data and there are some columns containing dates. I get the dates from an API in this format: 'YYYY-MM-DD HH:mm:ss'. Then i modify it using the columns.render function like this:

Before i init the DataTable i set the moment:

But it still doesn't sort the dates correctly:

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,117Questions: 26Answers: 4,916
    edited March 2019

    I looks like your code works in this example:
    http://live.datatables.net/zafofuka/1/edit

    Filter the table by 2011 for a good example. I think I'm seeing it correctly - I'm used to having the format MM/DD/YYYY :smile:

    Did you load the datetime-moment.js plugin as described here:
    https://datatables.net/blog/2014-12-18#Operation

    Can you post a test case or update mine to show the issue?

    Kevin

  • cmrtncmrtn Posts: 4Questions: 1Answers: 0

    First of all, thanks for the fast reply. I initialize my columns a little bit different to modify the columns.

    As you can see in this example: http://live.datatables.net/zafofuka/4/

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    The issue here is that you are returning a formatted date that DataTables doesn't know how to parse for all data request types (display, sort, type, filter). What you need to do is return an ISO string for sort and type, while returning your formatted string for display and filter.

    Allan

  • cmrtncmrtn Posts: 4Questions: 1Answers: 0

    thanks for your reply, Allan. could you please give me some code examples of how to return sort and type?

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    Hi @cmrtn ,

    You would use option columns.render for that - there's some examples on that page.

    Cheers,

    Colin

  • cmrtncmrtn Posts: 4Questions: 1Answers: 0

    thanks for all the answers, i got it :-)

This discussion has been closed.