datatable order value "order" code example

Example 1: datatables sorting order

// 3 is the column index, starting from 0 at the leftmost
$('#table').DataTable( {
   order: [[ 3, "desc" ]] // or "asc" for ascending
} );

// to sort on multiple rows
$('#example').DataTable( {
	order: [[ 3, 'desc' ], [ 0, 'asc' ]]
} );

// if using legacy datatables (initialization with lowercase dataTable)
aaSorting: [[3, "desc"]]

Example 2: datatable get order column

var table = $('#example').DataTable();

var order = table.order();
alert( 'Table is ordered by column: ' + order[0][0] + ', direction:' + order[0][1]);

var title = table.column(order[0][0]).header();
alert( 'Ordering column title: ' + $(title).html() );