Can not for the life of me get datatables to sort properly

Can not for the life of me get datatables to sort properly

SEJeffSEJeff Posts: 4Questions: 0Answers: 0
edited August 2009 in General
No matter what I try datatables is defaulting to sorting by the first column. Even with ""aoSorting": [ [3, 'desc'],]," datatables refuses to sort by column 3 (True / False). Even when trying to sort [0, 'desc] to invert the host name sorting it didn't work. Can someone help me see what I've done wrong here?

To the author/s of datatables, "This has got to be the nicest javascript table sorting script there is. Thankyou for saving me time!".

Here is what the js looks like:
$(document).ready(function() {
HostTable = $('#dataTable').dataTable( {
// Save a cookie with the sorting preferences
// Commented to figure out why sorting by health status is borked
//"bStateSave": true,

"bAutoWidth": false,

// Allow pagination and default to 100 results
"bPaginate": false,
"bLengthChange": true,
"iDisplayLength": 100,
"bProcessing": true,

// After adding the hardware column, manually
// specifying the width fixed sizing issues.
"aoColumns": [ {"sWidth": 20, "sType": "html"},
{"sWidth": 30},
{"sWidth": 25},
{"sWidth": 5}
"aoSorting": [ [3, 'desc'],],

// Numbered pages instead of < and > buttons
"sPaginationType": "full_numbers",
} );
} );

The table looks roughly like this:

System NameKernelHardwareHealthy

host12.6.20HP ProLiant DL360 G6True
host22.6.31_rc8.testHP ProLiant DL365 G5False
host32.6.9.el4.customDell PowerEdge 1950True


  • SEJeffSEJeff Posts: 4Questions: 0Answers: 0
    Changing aoSorting to aaSorting fixed this up. *facepalm*

    Thanks again for kickass software!
  • allanallan Posts: 62,448Questions: 1Answers: 10,251 Site admin
    Hi SEJeff,

    Good to hear you got this sorted. The sorting is expecting an array of arrays, rather than an array of objects, hence the 'aa' prefix :-). Easy when you know how... I might make future version of DataTables throw up a console warning if an unknown option is found.

  • SEJeffSEJeff Posts: 4Questions: 0Answers: 0
    b, a, and aa makes so much more sense now. It would be helpful to document that somewhere if you haven't already.

    Perhaps just a debug option would be good?

    oTable = ..... function(
    "bDebug": true,

    In other news, is there a suggested way to turn on / off pagination on the fly? Being very new to js (but not to programming) I'm not sure of the best way. Trying something like oTable.fnSettings("bPagination") = true; doesn't exactly work.
  • allanallan Posts: 62,448Questions: 1Answers: 10,251 Site admin

    The prefixes I use are a fairly common programming technique, which I find particularly useful in a loose type language such as Javascript - see for details.

    About a debug option - yes this is certainly something on my to-do list (although it will be a while before that one gets done I suspect), and it will be a build option (i.e. it would be a different JS file) such that the debug trace information won't bog down the main program when deployed.

    Regarding the option of changing the pagination feature during run time. This isn't possible with DataTables at the moment (where did you get the idea that you might be able to do something like fnSettings("bPagination") - this function doesn't take any arguments?). What you can do is "simulate" this, by hiding the paging controls (see for ID/class names) and setting the disable length to -1.

  • SEJeffSEJeff Posts: 4Questions: 0Answers: 0
    Playing with datatables the day I posted the original question was my very first day of javascript / jquery... Since I've not found an equivalent of python's pprint or perl's DataDumper just yet, I was just trying without much luck to bang around and find something.
This discussion has been closed.