Sort spring form:checkbox column

Sort spring form:checkbox column

ryansfryinryansfryin Posts: 2Questions: 0Answers: 0
edited February 2013 in General
Hello everyone,

I was successfully able to sort a regular vanilla HTML checkbox column using the following code:

[code]
$.fn.dataTableExt.afnSortData['dom-checkbox'] = function ( oSettings, iColumn )
{
var aData = [];
$( 'td:eq('+iColumn+') input', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
aData.push( this.checked==false ? "1" : "0" );
} );
return aData;
};
[/code]

However, I am using the Spring 3 form tags library, specifically a which generates a regular HTML checkbox in addition to a hidden input which determines if the checkbox is on or off. This is what one of the Select column cells would look like:
[code]




[/code]

Is there a way I can sort a column of spring form checkboxes? Does anyone have any suggestions on how to tackle this?

Replies

  • ryansfryinryansfryin Posts: 2Questions: 0Answers: 0
    edited March 2013
    I figured it out. The solution was pretty easy, just took me a bit to see it. Here is the code I used:

    [code]
    $.fn.dataTableExt.afnSortData['dom-checkbox'] = function ( oSettings, iColumn )
    {
    var aData = [];
    $( 'td:eq('+iColumn+') input:checkbox', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
    aData.push( this.checked==false ? "1" : "0" );
    } );
    return aData;
    };
    [/code]

    I added the :checkbox selector to input so that it only looks for checkboxes. Since Spring form:checkbox generates two inputs, one checkbox, and one hidden, the original code was finding both and breaking.
This discussion has been closed.