Toggle column visibility by class name

Toggle column visibility by class name

fmsolbakkenfmsolbakken 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

Answers

  • allanallan Posts: 63,839Questions: 1Answers: 10,518 Site admin
    Answer ✓

    columns.visible()

    This returns a DataTables API instance, so ! columns.visible() is always going to be false.

    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

  • fmsolbakkenfmsolbakken Posts: 3Questions: 2Answers: 0

    Worked fine! Thanks.

This discussion has been closed.