Jquery Datatables - date time sort not working even after implementing moment
Jquery Datatables - date time sort not working even after implementing moment
jivo
Posts: 4Questions: 1Answers: 0
Have tried local as well as link
">
">
${(m.createdAt?datetime)!}</td>
js code - $.fn.dataTable.moment( 'MM/dd/yyyy hh:mm:ss A');
tried $.fn.dataTable.moment( 'MM/dd/yyyy hh:mm:ss A zzz');
tried $.fn.dataTable.moment( 'MM/dd/yyyy hh:mm:ss a zzz' );
Nothing seems to work, Please suggest what am I missing?
This discussion has been closed.
Answers
<script type="text/javascript" src="<@s.url value='/js/lib/moment.min.js' encode="false"/>"></script>
<script type="text/javascript" src="<@s.url value='/js/lib/datetime-moment.js' encode="false"/>"></script>
<script type="text/javascript" src="https://cdn.datatables.net/plug-ins/1.10.16/sorting/date-dd-MMM-yyyy.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/plug-ins/1.10.16/sorting/datetime-moment.js"></script
Take a look at the moment docs for the formatting info. Looks like you will want something more like
$.fn.dataTable.moment( 'MM/D/YYYY HH:mm:ss a z' );
The docs mention something about using
z
orzz
as being deprecated for defining the Time Zone. You may want to look at the notes and make sure you have everything needed.Kevin
Thank you for your reply, Kevin!
Even if I remove the timezone, still no luck
Freemarker Code:
<#setting datetime_format="MM/dd/yyyy hh:mm:ss a">
<td>${m.createdAt?datetime}</td>
JS Code:
$.fn.dataTable.moment( 'MM/dd/YYYY hh:mm:ss a' );
Thank you for your reply, Kevin!
Even if I remove the Time Zone, still no luck.
HTML(Freemarker Code)
<#setting datetime_format="MM/dd/yyyy hh:mm:ss a">
<td >${m.createdAt?datetime}</td>
JS Code
$.fn.dataTable.moment( 'MM/dd/yyyy hh:mm:ss a' );
I looked at the date incorrectly. You need
DD
, notdd
, for days formatted like09
. Also all of the data in that column needs to match the format otherwise Datatables will assume its text and sort it that way. Also looks like you needA
instead ofa
. Make sure to verify the format with the moment docs.If you are unable to get it to work please provide a link to your page or a test case replicating the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin