0

I am using datatables.min.js to display my listing in wordpress. I want to display records such that latest entries should be display first (ORDER BY ID DESC). My query is correct but for some reasons it is not displaying as per my query order by clause (ORDER BY id DESC). It is displaying the oldest records first. Anybody can help how to fix this issue ?

  • Possible duplicate of [jQuery DataTables sorting is not working](https://stackoverflow.com/questions/28862456/jquery-datatables-sorting-is-not-working) – LuFFy Jun 05 '17 at 09:36
  • Please post your DataTables initialization code and screenshot of how the table appears now. A link to your page would help as well, if that is possible. – Gyrocode.com Jun 05 '17 at 10:41

2 Answers2

2

Try this code

$(document).ready(function() {
    $('#example').DataTable( {
        "order": [[ 0, "desc" ]]
    } );
} );

Default ordering (sorting) https://datatables.net/examples/basic_init/table_sorting.html

Bhupesh
  • 883
  • 7
  • 16
0

Try Below Solution :

$(document).ready(function() {
    $("#patientStoryLst").DataTable({
        "sPaginationType" : "full_numbers",
        "iDisplayLength " : 5,
        "bJQueryUI" : true,
        "sDom" : 'rt',
        "aoColumns": [{"bSortable": false }, null, null, null, null, null, null, null, null, null, null],
        "aaSorting": [[0, 'desc']]
    });
});
LuFFy
  • 8,799
  • 10
  • 41
  • 59
  • Please avoid posting duplicate answers. Besides, the question is not clear yet you're suggesting sorting all columns as numbers which may be incorrect for this case. – Gyrocode.com Jun 05 '17 at 10:37
  • You shouldn't be answering if you're not sure that your answer is correct, there is little details in the question. Right now your answer looks like you've copied and pasted from somewhere else. – Gyrocode.com Jun 05 '17 at 11:16