fnRender issue in aoColumnDefs
fnRender issue in aoColumnDefs
Viper
Posts: 9Questions: 0Answers: 0
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?
[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?
This discussion has been closed.
Replies
[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?
[code]nThs[i].style.width = o.aoColumns[iVis].sWidth;[/code]
o.aoColumns[iVis] is undefined.
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