Jquery Datatables - date time sort not working even after implementing moment

Jquery Datatables - date time sort not working even after implementing moment

jivojivo 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?

Answers

  • jivojivo Posts: 4Questions: 1Answers: 0

    <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

  • kthorngrenkthorngren Posts: 6,474Questions: 22Answers: 1,414
    edited October 9

    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 or zz as being deprecated for defining the Time Zone. You may want to look at the notes and make sure you have everything needed.

    Kevin

  • jivojivo Posts: 4Questions: 1Answers: 0

    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' );

  • jivojivo Posts: 4Questions: 1Answers: 0

    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' );

  • kthorngrenkthorngren Posts: 6,474Questions: 22Answers: 1,414

    I looked at the date incorrectly. You need DD, not dd, for days formatted like 09. 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 need A instead of a. 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

Sign In or Register to comment.