Can't hide columns the first time a table is viewed. *SOLVED*

Can't hide columns the first time a table is viewed. *SOLVED*

luketheobscureluketheobscure Posts: 20Questions: 0Answers: 0
edited September 2011 in General
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.

Replies

  • luketheobscureluketheobscure Posts: 20Questions: 0Answers: 0
    edited September 2011
    Firebug is telling me this:

    Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIDOMHTMLTableRowElement.appendChild]
  • luketheobscureluketheobscure Posts: 20Questions: 0Answers: 0
    Looks like it's failing around this (line 2074 of v1.8.2):

    [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.
  • luketheobscureluketheobscure Posts: 20Questions: 0Answers: 0
    It gets weirder... If I set "oTable.fnSetColumnVis(i,false)" right before I set it to true it works fine while I'm stepping through it in firebug, but if I put that in my code it borks the view, but it doesn't throw any errors.
  • luketheobscureluketheobscure Posts: 20Questions: 0Answers: 0
    OK, it looks like the reason it's failing is because this line (2034) isn't working as intended

    [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.
  • luketheobscureluketheobscure Posts: 20Questions: 0Answers: 0
    Looks like I had this in my code a few times:

    [code]"bVisible": 'true'[/code]

    Changing that to this fixed the problem:

    [code]"bVisible": true[/code]
This discussion has been closed.