Switch two column's visibility with one click

Switch two column's visibility with one click

patricknypatrickny Posts: 15Questions: 7Answers: 0

Hello, I know how to Hide or Show a column with toggle-visibility
Toggle column: <a class="toggle-vis" data-column="2">Select Courses</a> - <a class="toggle-vis" data-column="3">Courses Enrolled</a>
combined with the technique on https://datatables.net/examples/api/show_hide.html.

However: Is there a way to Hide Column 2 and Show Column 3 with One Click? .. And then switch back to Show 2 and Hide 3?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    edited September 2020 Answer ✓

    Yes. Use column().visible(). Just modify the example a bit to specify the column, like this:

    table.column( 2 ).visible( ! table.column( 2 ).visible() ); 
    table.column( 3 ).visible( ! table.column( 3 ).visible() ); 
    

    KEvin

This discussion has been closed.