Can't hide columns the first time a table is viewed. *SOLVED*
Can't hide columns the first time a table is viewed. *SOLVED*
luketheobscure
Posts: 20Questions: 0Answers: 0
I'm tearing out my hair with this one. The problem I'm having is that the code to hide the columns is not getting executed the first time the table is viewed. This is part of an AJAX application, so there's lots of tables being created and destroyed on a single "page". Here's an example of the datatable initialization:
[code]
jQuery('#results_table').dataTable({
"bStateSave": true,
"bAutoWidth": false,
"bDestroy": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aaData": commodities_data,
"aoColumns": commodities_columns,
"bDeferRender": true,
"fnInitComplete": function() {
var oTable = jQuery('#results_area table').dataTable();
jQuery.each(oTable.fnSettings().aoColumns, function(i){
oTable.fnSetColumnVis(i,true);
if( oTable.fnSettings().aoColumns.length == (i+1) ){
oTable.fnSetColumnVis( 0, false );
oTable.fnSetColumnVis( 2, false );
oTable.fnSetColumnVis( 3, false );
filterTable();
}
});
}
});
[/code]
I've tried moving that "fnInitComplete" stuff to it's own function, tried calling it in fnDrawCallback, and tried a bunch of other things. I have to manually loop through and set them to visible to override some settings that seem to always linger when hiding columns on old tables. Setting the visibility in aoColumns doesn't help either.
EDIT: Figured it out, see last comment.
[code]
jQuery('#results_table').dataTable({
"bStateSave": true,
"bAutoWidth": false,
"bDestroy": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aaData": commodities_data,
"aoColumns": commodities_columns,
"bDeferRender": true,
"fnInitComplete": function() {
var oTable = jQuery('#results_area table').dataTable();
jQuery.each(oTable.fnSettings().aoColumns, function(i){
oTable.fnSetColumnVis(i,true);
if( oTable.fnSettings().aoColumns.length == (i+1) ){
oTable.fnSetColumnVis( 0, false );
oTable.fnSetColumnVis( 2, false );
oTable.fnSetColumnVis( 3, false );
filterTable();
}
});
}
});
[/code]
I've tried moving that "fnInitComplete" stuff to it's own function, tried calling it in fnDrawCallback, and tried a bunch of other things. I have to manually loop through and set them to visible to override some settings that seem to always linger when hiding columns on old tables. Setting the visibility in aoColumns doesn't help either.
EDIT: Figured it out, see last comment.
This discussion has been closed.
Replies
Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIDOMHTMLTableRowElement.appendChild]
[code]
if ( bAppend )
{
oSettings.aoData[i].nTr.appendChild(
oSettings.aoData[i]._anHidden[iCol]
);
}
[/code]
Before the failure, oSettings.aoData[i]._anHidden[iCol] is null, and oSettings.aoData[i]._anHidden is an array of five null values. i is 0.
[code] if ( oSettings.aoColumns[iCol].bVisible == bShow ) [/code]
At this point oSettings.aoColumns[iCol].bVisible is "true" (string) instead of true, so this statement evaluates to false and it doesn't hit the return on line 2036.
[code]"bVisible": 'true'[/code]
Changing that to this fixed the problem:
[code]"bVisible": true[/code]