Problem with sorting by date with DATABASE plugin

0

I have a problem with the ordering of a table with a Datatable plugin and I am doing a SQL query already ordered by a field and when I present the table with the plugin it reorders it in another way and I tried several ways without success .

  

SQL

$sql  = "SELECT * FROM $this->table ORDER BY date(data_cadastro) DESC";
  

DataTable

var tabela = $('#Compras').dataTable( {
            "aoColumns": [  null,null,null,null,null,{ "bSortable": false },{ "bSortable": false },{ "bSortable": false },{ "bSortable": false },null,{ "bSortable": false } ],

            "oLanguage": {
            "sEmptyTable": "Nenhum registro encontrado",
            "sInfo": "Mostrando de _START_ até _END_ de _TOTAL_ registros",
            "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"
            }

            });

        })
  

PHP

<?=date("d/m/Y", strtotime($x->data_cadastro)) ?>

Return sql:

14/03/2018
14/03/2018
14/03/2018
13/03/2018
12/03/2018

Result in the table:

14/03/2018
14/03/2018
13/03/2018
12/03/2018
14/03/2018
    
asked by anonymous 20.03.2018 / 15:48

2 answers

0

Thiago, the ordering in the datatable is by default (year-month-day).

In the column that contains the date, you can do:

<tr>
    <td data-order="DATAPADRAO">DATA_BR</td>
</tr>

More info

    
20.03.2018 / 17:45
0

In the face of several attempts I found a nice solution, but it generates an error that I could not decipher yet, but the result is what I need.

"aaSorting": [[6, 'DESC']],

This way I can sort by the column number the date format

"order": [[6, 'DESC']],

does not work.

  

the error generated

jquery.dataTables.min.js:84 Uncaught TypeError: p[((intermediate value)(intermediate value)(intermediate value) + "-" + o[c][1])] is not a function

Anyone can help me to delete this error !!!

    
20.03.2018 / 18:13