Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 597
smoak Avatar asked Feb 11 '11 00:02

smoak


People also ask

How to disable ordering in DataTables?

The ability to order data can be disabled using this option. Note that the ability to add or remove sorting of individual columns can be disabled by the columns. orderable option for each column. This parameter is a global option - when disabled, there are no sorting actions applied by DataTables at all.

How to remove sorting from DataTable column?

Use columnDefs option to remove sorting from a column. Pass column index in targets within [] (Indexing starting from 0) and set orderable to false . In the example, I removed sorting from email and salary column.

How to disable sorting in DataTable in c#?

You need to change the properties of the GridView then, not the DataTable. The GridView data is the thing getting sorted in this case, not the DataTable. @KevenDenen I already tried that. "AllowUserToOrderColumns" is False, and clicking it still sorts the data.


3 Answers

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": []
    });
})
like image 115
smoak Avatar answered Oct 24 '22 13:10

smoak


As per latest api docs:

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

More Info

like image 37
Ravi Kadaboina Avatar answered Oct 24 '22 14:10

Ravi Kadaboina


Try this:

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

this will solve your problem.

like image 28
FennRussel Avatar answered Oct 24 '22 13:10

FennRussel