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