Date is not sort in order

Date is not sort in order

anoopcranoopcr Posts: 8Questions: 2Answers: 0

I am retrieving the data from database and showing it in my html. My first column is date. Here is the sample output

01-01-2019  SBI_OD  Own Transfer    
01-01-2019  SBI_S   Own Transfer    
01-12-2018  SBI_OD  Initial         
01-12-2018  ICICI_S Initial         
01-12-2018  SBI_S   Initial         
01-12-2018  ICICI_S Debit           
01-12-2018  ICICI_S Debit           
01-12-2018  ICICI_S Debit           
01-12-2018  SBI_OD  Own Transfer    
01-12-2018  SBI_S   Own Transfer    
01-12-2018  ICICI_S Debit           
01-12-2018  ICICI_S Own Transfer    
01-12-2018  SBI_OD  Credit          
01-12-2018  SBI_S   Own Transfer    
02-01-2019  ICICI_S Debit           

As you can see, the date suppose to start with 01-12-2018, but its sorting from 01-01-2019. I have verified the post https://datatables.net/blog/2014-12-18 and added moment.min.js and datetime-moment.js to my site.

This is my code which will retrieve data from database on form submit using AJAX:

function analyzedata() {

   var data1 = $("#analyze_options_select").val();
   var yeardata = $("#year").val();
   var monthdata = $("#analyze_options_month").val();
    var startdate = $("#start_date").val();
   var enddate = $("#end_date").val();

     $.ajax({ 

            url  :ajaxurl,
            type :'POST',
            data: { 'action': 'analyzedata','analyze_options':data1,'analyze_options_month':monthdata,'year':yeardata,'start_date':startdate,'end_date':enddate},

            success: function(data){

                    $("#example tbody").html(data);
                    $.fn.dataTable.moment( 'dd-MM-YYYY' );


                        var table = $('#example').DataTable({

                        retrieve: true,
                        paging: false, 
                        columnDefs: [
                                        {
                                        targets:0,
                                        type: 'string'
                                        }
                                    ]
                        });

                        table.rows.add($(data)).draw();

                    }
        });

    }; 

As mentioned in the post, I have added code $.fn.dataTable.moment( 'dd-MM-YYYY' ); but its not working. Can someone guide me how to resolve this ?

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.