Date Time Sorting Questions
Date Time Sorting Questions
I have a dataTable with a date column in dd/mm/yyyy format and a time column in hh:mm format with times before 10:00 displaying as 9:59 not 09:59.
I need dataTables to understand those formats point 1.
I need to sort the table by default with the date column and then the time column both descending so the most recent date and time is first point 2.
I have read thru the other discussions on using moment.js and datetime-moment.js.
Am I going about this the right way by using these plugins?
just before the data table instantiation I declare:
$.fn.dataTable.moment( 'DD/MM/YYYY' );
$.fn.dataTable.moment( 'HH:mm' );
and in the table instantiation I have:
"order": [ [ 3, "desc" ], [ 4, "desc" ] ],
However I am getting in the time column:
9:58
9:57
9:56
10:04
10:03
10:02
What am i Missing here?
Thanks
Ken
This question has an accepted answers - jump to answer
Answers
Hi Ken,
What you have looks right to me. If that isn't working for you, can you give me a link to your page so I can help to debug it please?
Allan
Hi Allan,
Sorry I can't share the page as it is behind a login/password control system.
What i can tell you is I am using:
jquery.dataTables.min.js version 1.10.13
jquery.min.js version 1.11.1
moment.js version 2.8.4
datetime-moment.js "@depends DataTables 1.10+, Moment.js 1.7+"
Can I upload a copy of the HTML maybe?
Thanks for the support.
Ken
Hi Allan,
I have found a solution but not sure if it is a bug or not with moment.js and/or datetime-moment.js.
I manually added the leading 0 for times under 10:00 and the time column now sorts correctly.
Regards
Ken
I think you just use
H
in MomentJS if you want it to allow numbers without a leading 0 (24 hour format).HH
is with leading zeros. The Moment documentation is here.Allan