Is there a way to disable initial sorting for jquery DataTables?

JqueryJquery Datatables

Jquery Problem Overview


I'm using the jquery DataTables plugin. From their documentation:

> If sorting is enabled, then DataTables will perform a first pass sort on initialisation. You can define which column(s) the sort is performed upon, and the sorting direction, with this variable. The aaSorting array should contain an array for each column to be sorted initially containing the column's index and a direction string ('asc' or 'desc').

Is it possible to have sorting enabled but disable this first pass sort on initialization? I am currently doing the initial sort server side and need sorting functionality but don't need this initial sort functionality.

Jquery Solutions


Solution 1 - Jquery

Well I found the answer set "aaSorting" to an empty array:

$(document).ready( function() {
    $('#example').dataTable({
        /* Disable initial sort */
        "aaSorting": []
    });
})

For newer versions of Datatables (>= 1.10) use order option:

$(document).ready( function() {
    $('#example').dataTable({
        /* No ordering applied by DataTables during initialisation */
        "order": []
    });
})

Solution 2 - Jquery

As per latest api docs:

$(document).ready(function() {
    $('#example').dataTable({
        "order": []
    });
});

More Info

Solution 3 - Jquery

Try this:

$(document).ready( function () {
  $('#example').dataTable({
    "order": []
  });
});

this will solve your problem.

Solution 4 - Jquery

In datatable options put this:

$(document).ready( function() {
  $('#example').dataTable({
    "aaSorting": [[ 2, 'asc' ]], 
    //More options ...
    
   });
})

Here is the solution: "aaSorting": [[ 2, 'asc' ]],

2 means table will be sorted by third column,
asc in ascending order.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsmoakView Question on Stackoverflow
Solution 1 - JquerysmoakView Answer on Stackoverflow
Solution 2 - JqueryRavi KadaboinaView Answer on Stackoverflow
Solution 3 - JqueryFennRusselView Answer on Stackoverflow
Solution 4 - JqueryluchopintadoView Answer on Stackoverflow