Toggle column visibility by class name
Toggle column visibility by class name
fmsolbakken
Posts: 3Questions: 2Answers: 0
I have three columns with class 'epic' and a button defined with:
action: function (e, dt, node, config) {
var columns = oTable.columns('.epic');
columns.visible(!columns.visible());
//columns.visible(true);
}
The column.visible(!column.visible()); hides the three columns on first click on the button, but does not show them again
columns.visible(true); works fine
Any ideas why the columns will not show on second click on the button?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
This returns a DataTables API instance, so
! columns.visible()
is always going to befalse
.Try
columns.visible(!columns.visible()[0]);
That will get the first entry from the array. Assuming all three columns are always in sync visibility-wise, that should work okay.
Allan
Worked fine! Thanks.