Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81997

using columnsToggle to hide columns but not remove them from the DOM

$
0
0

Is there a way to use the columnsToggle option, but have the toggle hide columns instead of removing them from the DOM? The reason I ask is I need to assign classes to certain cells, and right now I can only come up with 2 ways:

var table = $('#example').DataTable();
var row = table.row('#row_'+d.data[i].ID);
var node = row.node();

$(node).find('.cssCompTot').addClass('Warn');

or

$(node). find('td').eq(7).addClass('Warn');

The problem with either method is, if the table column is set to be hidden on load (I am using cookies to allow a user to hide columns on load) this will never find the cell that needs to have the class hidden because it is removed from the DOM.

The other problem with the 2nd example is, if different columns are hidden in front of column 7, the position will change as well and the class is applied to the wrong cell.

I have tried using:

 table.row.cell(this.index(),7).node().addClass('Warn')

as well as

 $( table.row.cell(this.index(),7).node() ).addClass('Warn')

Viewing all articles
Browse latest Browse all 81997

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>