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'?
cmrtn
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
This discussion has been closed.
Answers
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
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
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/
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
andtype
, while returning your formatted string fordisplay
andfilter
.Allan
thanks for your reply, Allan. could you please give me some code examples of how to return sort and type?
Hi @cmrtn ,
You would use
option columns.render
for that - there's some examples on that page.Cheers,
Colin
thanks for all the answers, i got it :-)