Error sorting by date using Datatable and EN default

Asked

Viewed 136 times

0

Good afternoon

I have the code below and can not order by date, it orders only by day and not by day/year

is the first column, or target 0,

inserir a descrição da imagem aqui

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
   "date-br-pre": function ( a ) {
    if (a == null || a == "") {
     return 0;
    }
    var brDatea = a.split('/');
    return (brDatea[2] + brDatea[1] + brDatea[0]) * 1;
    console.log(brDatea);
   },

   "date-br-asc": function ( a, b ) {
    return ((a < b) ? -1 : ((a > b) ? 1 : 0));
    console.log(a);
    console.log(b);
   },

   "date-br-desc": function ( a, b ) {
    return ((a < b) ? 1 : ((a > b) ? -1 : 0));
     console.log(a);
    console.log(b);
   }
  } );
  $(document).ready(function() {

      $('#relatorio-principal').DataTable({
         columnDefs: [
            { type: 'date-br-desc', targets: 0 }
          ],
         "pageLength": 50,
          searchPlaceholder: "Procurar Registros",
        dom: 'Bfrtip',  
          buttons: [
              'copyHtml5',
              'excelHtml5',
              'csvHtml5'
          ],
          "language" : {
            "sEmptyTable": "Nenhum registro encontrado",
            "sInfo": "Mostrando  _START_ até _END_ de _TOTAL_ Resultados",
            "sInfoEmpty": "Mostrando 0 até 0 de 0 registros",
            "sInfoFiltered": "(Filtrados de MAX registros)",
            "sInfoPostFix": "",
            "sInfoThousands": ".",
            "sLengthMenu": "_MENU_ resultados por página",
            "sLoadingRecords": "Carregando...",
            "sProcessing": "Processando...",
            "sZeroRecords": "Nenhum registro encontrado",
            "sSearch": "Pesquisar",
            "oPaginate": {
                "sNext": "Próximo",
                "sPrevious": "Anterior",
                "sFirst": "Primeiro",
                "sLast": "Último"
            },
            "oAria": {
                "sSortAscending": ": Ordenar colunas de forma ascendente",
                "sSortDescending": ": Ordenar colunas de forma descendente"
            }
        },
     });

      $(".dataTables_filter label input").attr("placeholder","Pesquise aqui...");
      $('.dataTables_info').html(function(i, v){
        return v.replace(/(\d)/g, '<span class="number">$1</span>');
    });
  });

I am using version 1.10.19 of DATATABLE.

1 answer

0

In the columnDefs mute to

[{ type: 'date-br', targets: 0 }]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.