jQuery DataTables: Turn-Off / Customize the default sorting / initial sorting for jquery DataTables

By default jQuery DataTables plugin sorts the table alphabetically in ascending order using the first column. However, if this irritates you or does not fit your requirement then you can turn it off.

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

Sorting by-default using any of the column in any order

$(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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s