Datetime column not sorting correctly
Datetime column not sorting correctly
Link to test case: https://www.wd4g.com/WCGateway/DTDemoCase1.wc
Debugger code (debug.datatables.net): n\a
Error messages shown: n\a
Description of problem: See below
Hi, this is my first attempt at having a datetime column, so I'm probably missing something obvious, but I've searched the forums and implemented the suggestions I found, but it is not quite right.
The column searches correctly on the date but the times are not right, it should be the most recent at the top, this is the code I have added, so far:
Before the DT init section I added:
$.fn.dataTable.moment('DD/MM/YYYY'); \\ This already existed and is needed for simple date fields
$.fn.dataTable.moment('DD/MM/YYYY HH:MM:SS A'); \\ This I added for the new datetime fields
In the column definition section I added:
{ targets: [0], type: "moment-DD/MM/YYYY HH:MM:SS A"},
If someone could please take a look and advise that would be greatly appreciated.
Thanks, Chris
This question has an accepted answers - jump to answer
Answers
This is an example of your datetime value:
The format of
DD/MM/YYYY HH:MM:SS A
is not correct. See the moment display docs for the correct formatting tokens. I believe the format should be this:Note the
mm
for minutes andss
for seconds.Kevin
Also it's not recommended to set the
columns.type
. Datatables type detection will set the type appropriately as long as all the values in the column match the format. If there is a mismatch then type detection will default to string regardless of thetype: "moment-DD/MM/YYYY HH:MM:SS A"
setting. Removecolumns.type
from the config.Kevin
That works, thank you so much Kevin