fnRender issue in aoColumnDefs

fnRender issue in aoColumnDefs

ViperViper Posts: 9Questions: 0Answers: 0
edited June 2012 in DataTables 1.9
My code for column preprocessing
[code]'aoColumnDefs': [
{
'bSearchable': false,
'bVisible': true,
'bSortable': false,
'bUseRendered': false,
'fnRender': function(o, val){
return o.aData[o.oSettings.aoColumns[o.iDataColumn].mDataProp];
},
'aTargets': [0]
},
{
'bSearchable': true,
'bVisible': true,
'bSortable': true,
'bUseRendered': false,
'fnRender': function(o){
if (o.mDataProp == 'parent_event_id') {
//o.oSettings.aoColumns[o.iDataColumn].bVisible = false;
console.log(1);
} else {
console.log(0);
}

return o.aData[o.oSettings.aoColumns[o.iDataColumn].mDataProp];
},
'aTargets': [1]
}
][/code]

If I do console.log(o.oSettings.aoColumns[o.iDataColumn].bVisible); for colums 1 I see that is true. But when I trying to set it in 'if' statement I get an error [quote]a.aoColumns[o] is undefined[/quote]

Why I can't set it to false in fnRender callback?

Replies

  • ViperViper Posts: 9Questions: 0Answers: 0
    Hmm... If I move o.oSettings.aoColumns[o.iDataColumn].bVisible = false; to fnDrawCallback dataTables won't hide this column.

    [code]...
    'fnDrawCallback': function(oSettings){
    oSettings.aoColumns[1].bVisible = false;
    }[/code]

    My table have a seven columns, but I can't hide any columns in fnDrawCallback. Looks like a bug?! Or not?
  • ViperViper Posts: 9Questions: 0Answers: 0
    I found that problem is in the next line in dataTables.js
    [code]nThs[i].style.width = o.aoColumns[iVis].sWidth;[/code]

    o.aoColumns[iVis] is undefined.
  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin
    > oSettings.aoColumns[1].bVisible = false

    This is not the way to change the column visibility since there is no 'set' hook in Javascript (at least, not that is widely supported yet!). If you want to change the column visibility you need to use fnSetCoumnVis , otherwise DataTables has no way of enacting the change.

    Allan
This discussion has been closed.