DataTables logo DataTables

via Ad Packs
fnRender issue in aoColumnDefs
  • ViperViper
    Posts: 9
    My code for column preprocessing
    '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]
    	}
    ]

    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
    a.aoColumns[o] is undefined

    Why I can't set it to false in fnRender callback?
  • ViperViper
    Posts: 9
    Hmm... If I move o.oSettings.aoColumns[o.iDataColumn].bVisible = false; to fnDrawCallback dataTables won't hide this column.

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

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

    o.aoColumns[iVis] is undefined.
  • allanallan
    Posts: 15,556
    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.
← All Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Support

Get useful and friendly help straight from the source.

In this Discussion