Can not for the life of me get datatables to sort properly
Can not for the life of me get datatables to sort properly
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
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
This discussion has been closed.
Replies
Thanks again for kickass software!
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.
Regards,
Allan
Perhaps just a debug option would be good?
oTable = ..... function(
"aaSort"....
"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.
The prefixes I use are a fairly common programming technique, which I find particularly useful in a loose type language such as Javascript - see http://en.wikipedia.org/wiki/Polish_notation 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 http://datatables.net/styling for ID/class names) and setting the disable length to -1.
Regards,
Allan