default sort by date in mm/dd/yyyy format

default sort by date in mm/dd/yyyy format

nitinb82nitinb82 Posts: 12Questions: 3Answers: 0
edited August 2018 in Free community support

Hi,
I have a table with dates in it in the mm/dd/yyyy format in the 7th column. I used the
https://datatables.net/plug-ins/sorting/date-dd-MMM-yyyy plugin to sort the table by date when rendered the first time in the webpage (latest entries first). However, it still sorts them as if they are string. Here is the code

 { "type": "mm/dd/yyyy", "targets": 7 }],
 "order": [[ 7, "desc" ]],

I loaded this library //cdn.datatables.net/plug-ins/1.10.19/sorting/date-dd-MMM-yyyy.js

What am I doing wrong? How can I sort the table by date with the latest entries first?
Thanks!

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    You are using a deprecated plug-in.
    You need this one:
    https://datatables.net/blog/2014-12-18

  • nitinb82nitinb82 Posts: 12Questions: 3Answers: 0

    Thanks!
    I can't get that to work either. I loaded the two libraries
    //cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js
    //cdn.datatables.net/plug-ins/1.10.19/sorting/datetime-moment.js
    with the following code during initialization:

                        $(document).ready(function() {
                        $.fn.dataTable.moment( 'mm/dd/yyyy' );
                        $('#samples').DataTable({
                           "columnDefs": [{"width": "10%", "targets":1}],
                           "order": [[ 7, "desc" ]],
                        });
    

    What is wrong with the above code?

This discussion has been closed.