Hidden column + checkbox column sorting bug

Hidden column + checkbox column sorting bug

newtodatatablesnewtodatatables Posts: 31Questions: 0Answers: 0
edited May 2011 in DataTables 1.8
I am using the checkbox function in the DataTables. However, whenever I hide a column, the checkbox column sorting function stops functioning and I get a javascript: undefined error. Other columns sorting function is still working. Really wonder what is wrong! :(

However, if I unhide all the columns, the sorting function for the checkbox column will work.

This is my table init 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==true ? "1" : "0" );
} );
return aData;
}

oTable = $("#table").dataTable( {

"bProcessing": true,
"bAutoWidth" : false,
"aoColumns" : [

{ sWidth : "10%" },
{ sWidth : "45%" },
{ sWidth : "8%" },
{ sWidth : "27%", "bVisible": false},
{ sWidth : "10%" },
{ "sSortDataType": "dom-checkbox" }
],
"sDom": 'RC<"clear">lfrtip',
"sAjaxSource": "data.jsp",
"oLanguage": {
"sSearch": "Search all columns:"
},
"oColReorder": {
"iFixedColumns": 1
}

} );
[/code]

and my table headings.

[code]


App ID
Name
Version
Custodian
Status
Check





[/code]

Replies

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    That would be the selector...

    [code]
    $( 'td:eq('+iColumn+') input'
    [/code]
    It's counting the visible columns - but as you not you've hidden one - thus the problem. So you need to convert the 'true' index to the visible index. There is an internal function called _fnColumnIndexToVisible which you can use to do that (oSettings.oApi._fnColumnIndexToVisible( iColumn )) - but note that it is an internal function. In fairness I'd say it's very unlikely to change in the 1.x series, but it might in future.

    Allan
  • newtodatatablesnewtodatatables Posts: 31Questions: 0Answers: 0
    Thank you for your reply! I will post my working solution if i succeed.
This discussion has been closed.