Sorting on checkbox cols

Sorting on checkbox cols

sronsieksronsiek Posts: 52Questions: 11Answers: 0
edited July 2013 in DataTables 1.9
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.

Replies

  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin
    I suspect you might have upgraded your jQuery as all? They changed how nodes which are not in the document are ordered. I'd updated one of the other example files, but had forgotten about that one. It has been updated now.

    Allan
  • sronsieksronsiek Posts: 52Questions: 11Answers: 0
    Yes, you're right in that I did upgrade jquery (from1.7.2 -> 1.9.1), however using the modified version on that page still does not work for me. As far as I can see you have just removed the 'if' statements in the lines preceding the aData.push.

    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]
  • sronsieksronsiek Posts: 52Questions: 11Answers: 0
    edited July 2013
    Oops - I just saw the page content change in dom_sort.html Maybe I had the old version cached.

    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.
  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin
    edited July 2013
    Can you link to a test case showing the problem then please?

    Allan
  • sronsieksronsiek Posts: 52Questions: 11Answers: 0
    http://test123.demo.makalumedia.com/

    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!
  • sronsieksronsiek Posts: 52Questions: 11Answers: 0
    The link is there as requested.

    I also could not get fnFilter to work in regex mode (see pairings.js) ... but that's another issue.
  • sronsieksronsiek Posts: 52Questions: 11Answers: 0
    Little ping.
  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin
    Thanks for bumping this - I didn't have time to look at it before.

    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
  • sronsieksronsiek Posts: 52Questions: 11Answers: 0
    I fear this might have stagnated despite the good intentions. Would love to be wrong ;)
  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin
    Yes it had stagnated, but it will yet be fixed :-). I've just had to concentrate on other things first unfortunately, but I'll be coming back to this - hopefully soon.

    Allan
This discussion has been closed.