jQuery DataTables: how to sort by specific column?

Snow_Mac picture Snow_Mac · Oct 24, 2011 · Viewed 86.1k times · Source

Here's the page:

http://csuvscu.com/

I need to sort by the Date Column, right now it needs to read Nov 6, Nov 5 and lastly Oct 7.

How do I do this?

Answer

shaheenery picture shaheenery · Oct 24, 2011

Your Current Code:

$('table').dataTable({
    // display everything
    "iDisplayLength": -1
});

What you could do:

oTable = $('table').dataTable({
    // display everything
    "iDisplayLength": -1
});

oTable.fnSort( [ [0,'desc'] ] ); // Sort by first column descending

But as pointed out in the comment below, this may be a cleaner method:

$('table').dataTable({
    // display everything
    "iDisplayLength": -1,
    "aaSorting": [[ 0, "desc" ]] // Sort by first column descending
});