Date Sorting Issue
Date Sorting Issue
Uzairkhan92
Posts: 36Questions: 10Answers: 0
Link to test case:
https://jsfiddle.net/s6upbqn8/5/
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
In the Column tenth (Member Since) I am facing Sorting issue due to new year.
Can you plz check.
Answers
You would probably need to use a plug in for date time sorting.
This one is good:
https://datatables.net/plug-ins/sorting/datetime-moment
Here is a thread from SO with more information:
https://stackoverflow.com/questions/53238318/html5-javascript-datatables-order-sort-of-columns/53238593#53238593
That thread is very old, dataTables supports date time sorting.
You are right. The thread is old and data tables has always been supporting date time sorting.
The nice thing about the plug-in is that it auto-detects date columns. I never need your "target" definitions in "columDefs" and no modifications of my HTML either.
Before I used the ultimate date plugin I had to do the same thing as you. For my dozens of data tables with hundreds of dateTime fields this meant a lot of code redundancy!
https://datatables.net/plug-ins/sorting/datetime-moment
I'd really strongly suggest against doing that. If the auto-detection that @rf1234 mentions doesn't detect your data format, then forcing it to a date type could break things. Use the formatting options to define the formats yo have that you want to sort.
Allan