DataTables 1.9.4: Can't Sort (With Test Case)
DataTables 1.9.4: Can't Sort (With Test Case)
machineghost
Posts: 9Questions: 0Answers: 0
My issue is pretty simple: no matter what options I enable or disable, I can't seem to get DataTables to sort my data. It "focuses" on the column when I click it, the arrow changes from up to down when I click it, and the aria-sort attribute also changes ... but the table doesn't actually sort.
I created a test case here:
http://live.datatables.net/utuxil/edit#preview
If you scroll to the "expression value" column (or just enter some values in a different column) and try clicking on the header you can see the problem. I've tried ... well it feels like I've tried every sorting option in the list, but none have helped. I even made a second test case to show that the two most obvious ones (sType and sSortDataType) don't help:
http://live.datatables.net/exaceq/edit#preview
I imagine I must be missing just one key option (how many ways can there be to make DataTables do *everything* involved in sorting except actually sort?) ... does anyone out there have any idea what that one key option might be?
I created a test case here:
http://live.datatables.net/utuxil/edit#preview
If you scroll to the "expression value" column (or just enter some values in a different column) and try clicking on the header you can see the problem. I've tried ... well it feels like I've tried every sorting option in the list, but none have helped. I even made a second test case to show that the two most obvious ones (sType and sSortDataType) don't help:
http://live.datatables.net/exaceq/edit#preview
I imagine I must be missing just one key option (how many ways can there be to make DataTables do *everything* involved in sorting except actually sort?) ... does anyone out there have any idea what that one key option might be?
This discussion has been closed.
Replies
The key thing here to know is that sorting in DataTables occurs (usually) on the values which are read when the row is added to the table (in this case at initialisation time). It does not reevaluate the HTML for sorting on each sort as that could be horrifically slow.
However, sometimes that is needed, as is the case of your input and select elements here. For that you need to use live DOM sorting. There is an example of how to do that here: http://datatables.net/release-datatables/examples/plug-ins/dom_sort.html .
Allan
I did have one problem though: I discovered I had to add the following also:
$.fn.dataTableExt.afnSortData['std'] = function(oSettings, iColumn) {
return $.map(oSettings.oApi._fnGetTrNodes(oSettings), function(tr, i) {
return $('td:eq(' + iColumn + ')', tr).text();
});
};
Without it, my non-input/non-select (ie. plain text) columns wouldn't sort. Perhaps that should be added to the example code?
Either way, thanks again.
Yes it is a bit of a workaround at the moment - I'm still working on how best to integrating it directly into DataTables without increasing the size of the library significantly, while retaining flexibility.
Allan