Column Sorting US date format

Column Sorting US date format

chandra28chandra28 Posts: 6Questions: 0Answers: 0

Hi,
I have a column of dates which has this format MM/DD/YYYY. Sorting is not properly working for this format(MM/DD/YYYY). Could you help me?

Replies

  • kthorngrenkthorngren Posts: 20,369Questions: 26Answers: 4,777

    Are you using the code described in this blog?

    Kevin

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    Also, could you use the debugger so we can see what configuration you are working with.

    Allan

  • chandra28chandra28 Posts: 6Questions: 0Answers: 0

    Hi,
    This is the code and version which one is using in my project.

    Reference:
    https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js

    Js:
    function tablesorting() {
    $.fn.dataTable.ext.errMode = 'none';
    $('#tblClassDetails').DataTable({
    "order": [[3, "desc"]],
    paging: false,
    "searching": false,
    "info": false
    });
    }

    Everything is working fine except date column(US format). For example: 2/28/2017, 2/8/2017. It is sorting only based on month.It is not considering the date.

  • chandra28chandra28 Posts: 6Questions: 0Answers: 0

    If I use moment.js I'm getting this error. Uncaught TypeError: $.fn.dataTable.moment is not a function at tablesorting

    Ref: https://cdn.datatables.net/plug-ins/1.10.15/sorting/datetime-moment.js

    JS:
    function tablesorting() {
    $.fn.dataTable.ext.errMode = 'none';
    $.fn.dataTable.moment('M, D, YYYY');
    $('#tblClassDetails').DataTable({
    "order": [[3, "desc"]],
    paging: false,
    "searching": false,
    "info": false
    });
    }

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    You would need to include MomentJS on the page. You also need to change the format to match the data that you are using. Have a read through the link that @kthorngren gave.

    Allan

  • chandra28chandra28 Posts: 6Questions: 0Answers: 0

    If I use moment.js I'm getting this error. Uncaught TypeError: $.fn.dataTable.moment is not a function at tablesorting

    Ref: https://cdn.datatables.net/plug-ins/1.10.15/sorting/datetime-moment.js

    JS:
    function tablesorting() {
    $.fn.dataTable.ext.errMode = 'none';
    $.fn.dataTable.moment('M, D, YYYY');
    $('#tblClassDetails').DataTable({
    "order": [[3, "desc"]],
    paging: false,
    "searching": false,
    "info": false
    });
    }

  • chandra28chandra28 Posts: 6Questions: 0Answers: 0

    Where I have to change the format exactly? I'm new to Jquery. Could you help to change the format?

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    $.fn.dataTable.moment('M, D, YYYY');

    That is telling DataTables to look for the format M, D, YYYY. Which doesn't match your data so you would need to change it to match your format. The full list of options is available in the Moment documentation.

    Uncaught TypeError: $.fn.dataTable.moment is not a function at tablesorting

    Happy to look at a test case showing the issue and help debug it.

    Allan

This discussion has been closed.