Take the 2-minute tour ×

I am working on datatable plugin in Jquery. And have to set the default column by which the data is sorted so I mean that :

I have a table with 4 columns and by default the data is sorted by column no 1, I want that the data should be sorted by column number 2 or 3.

How that can be done:

    "bJQueryUI" : true,
    "sDom" : 'R<"H"lfr>t<"F"ip<',
    "aoColumns" : [ 
        {"bSortable" : false}, 
        {"bSortable" : false}, 
        {"bSortable" : false}
    "aaSorting": [[ 2, "desc" ]]

I specified that in "aaSorting" but not getting the result.

Please shed some light?

share|improve this question
live.datatables.net/amipoq/8/edit this at least works, seems problem somewhere else –  eicto Oct 14 '12 at 7:27

2 Answers 2

up vote 12 down vote accepted

The example in the datatable api does it like this:

$(document).ready(function() {
  var oTable = $('#example').dataTable();

  // Sort immediately with columns 0 and 1
  oTable.fnSort( [ [0,'asc'], [1,'asc'] ] );
} );
share|improve this answer
I want to sort the table on 2 column not on 0 or 1 –  ankur verma Oct 14 '12 at 7:25
Thanks @kannix.. –  ankur verma Oct 14 '12 at 7:44
+1, nice answer :) –  Sagar Panchal Apr 28 at 12:27

I know you got the answer, but just for record

You can also sort it from server side by using the parameter


it is basically an integer 0,1,2.. means first,second,third.. column. so you can write a switch before fetching the data..

 String sortOn = 'firstcolumnname'; //default
 switch(params.iSortCol_0 as int) {

   case 0:
     sortOn = 'id';


and include this in order by of your query

 order by ${sortOn}

Hope this will help

share|improve this answer

Your Answer


