0

datetime sorting is not working , I have an array of datetimes , I explode it and echo 'end($arrayExploded)' to get the last array.

That's what is printed

https://i.stack.imgur.com/JVmet.png

the date format is day/month/year

but order asc is not working , it should be 06/05/2019 the first date to show.

I've tried to use order asc , didn't work. I've tried to use date-euro plugin for datatable , but didn't work either.


  $(document).ready( function () {
      $('#table_id').DataTable({

          "order":[[5,"asc"]] ,    
                 "pageLength": 10,


           "bJQueryUI": true,
                "oLanguage": {
                    "sProcessing":   "Processando...",
                    "sLengthMenu":   "Mostrar _MENU_ registros",
                    "sZeroRecords":  "Não foram encontrados resultados",
                    "sInfo":         "Mostrando de _START_ até _END_ de _TOTAL_ registros",
                    "sInfoEmpty":    "Mostrando de 0 até 0 de 0 registros",
                    "sInfoFiltered": "",
                    "sInfoPostFix":  "",
                    "sSearch":       "Buscar:",
                    "sUrl":          "",
                    "oPaginate": {
                        "sFirst":    "Primeiro",
                        "sPrevious": "Anterior",
                        "sNext":     "Seguinte",
                        "sLast":     "Último",

                    }


                }


    } );      
      });





</script> ```



Machavity
  • 30,841
  • 27
  • 92
  • 100
Lucas Ln
  • 77
  • 1
  • 10
  • 3
    Possible duplicate of [Datatable date sorting dd/mm/yyyy issue](https://stackoverflow.com/questions/12003222/datatable-date-sorting-dd-mm-yyyy-issue) – Dimitris Filippou Jun 06 '19 at 12:13

2 Answers2

0

You need to use data-order attribute on TD of date column. In this attribute, you should have date format as YYYYMMDD as below:

<td data-order="2019-06-06"> 06/06/2019</td>

After making this, your column will sort on data-order value instead of showing value which will work correctly.

Hope it helps you!!

Rohit Mittal
  • 2,064
  • 2
  • 8
  • 18
0

I think i got it using momentjs and put this $.fn.dataTable.moment('DD/MM/YYYY HH:mm:ss'); in my datatable

  $(document).ready( function () {

  $.fn.dataTable.moment('DD/MM/YYYY HH:mm:ss');
  $('#table_id').DataTable({ ...
Lucas Ln
  • 77
  • 1
  • 10