Sorting on checkbox cols
Sorting on checkbox cols
sronsiek
Posts: 52Questions: 11Answers: 0
Hi,
I used the examples on this page http://datatables.net/examples/plug-ins/dom_sort.html
in my application to sort columns containing check-boxes and select options.
Specifically I'm using: "sSortDataType": "dom-checkbox", "aTargets": [ 6, 7, 8, 9 ]
in aoColumnDefs in a table.
This worked in Datatables 1.9.1, but now I've upgraded to 1.9.4 the code seems broken.
I have walked through it in a debugger & see the aData array seems to be correctly built
and returned, but there is no re-sort after the function completes. Appears as though there
is no refresh (fnDraw needed somewhere?)..
Any help appreciated ...
S.
I used the examples on this page http://datatables.net/examples/plug-ins/dom_sort.html
in my application to sort columns containing check-boxes and select options.
Specifically I'm using: "sSortDataType": "dom-checkbox", "aTargets": [ 6, 7, 8, 9 ]
in aoColumnDefs in a table.
This worked in Datatables 1.9.1, but now I've upgraded to 1.9.4 the code seems broken.
I have walked through it in a debugger & see the aData array seems to be correctly built
and returned, but there is no re-sort after the function completes. Appears as though there
is no refresh (fnDraw needed somewhere?)..
Any help appreciated ...
S.
This discussion has been closed.
Replies
Allan
What should the change be - or could you point me to one of the other pages you mention?
Just for info - I found previously the example code brakes when there are hidden colums to the left of the one being sorted. The following fixed this, but I'm sure you could come up with a more elegant solution ;)
[code]
num_preceeding_hidden_cols = function( oSettings, thisCol )
{
var hidden = 0
var i=0
while ( i < thisCol ) {
if ( oSettings.aoColumns[i].bVisible == false )
hidden += 1
i += 1
}
return hidden
}
/* Create an array with the values of all the checkboxes in a column */
$.fn.dataTableExt.afnSortData['dom-checkbox'] = function ( oSettings, iColumn )
{
var aData = [];
var hidden = num_preceeding_hidden_cols( oSettings, iColumn )
$( 'td:eq('+(iColumn-hidden)+') input', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
// if ( this.type == 'checkbox' )
aData.push( this.checked==true ? "1" : "0" );
} );
return aData;
}
[/code]
Tried that - but still no joy. I'm rendering the checkboxes client-side using mRender.
I removed all col hiding, and initial sorting. In the debugger I see the new code build an array that reflects the checkbox settings in the column I attempt to sort - but there is no attempt to render an update.
Allan
There are no hidden cols in the table shown. Sorting on all cols works except the 4 to the right - all of which are dom-checkbox.
Data table options are defined in pairings.js
Thanks for looking into this - much appreciated!
I also could not get fnFilter to work in regex mode (see pairings.js) ... but that's another issue.
I've just spent a little while looking into it and the problem is the use of mRender in combination with the live DOM sorting plug-ins - the two are incompatible due to the way DataTables currently operates.
The DOM sorting information is retrieved, but the sorting information from mRender then (incorrectly) overwrites that data. This causes the issue that is being seen here.
This is something that I will look at putting a fix in for v1.10 - I've open a tracking bug here: https://github.com/DataTables/DataTables/issues/211 . I hope to get a chance to look at fixing it tomorrow, although it won't be back ported to 1.9.
Allan
Allan