You can allow users to hide or show columns at runtime. All you have to do is to enable column collapsing:
table.setColumnCollapsingAllowed(true);
That will render a little menu to play with columns' visibility as shown in the next screenshot:
If you want to disable column collapsing for a certain column, you can do something similar to the following code snippet:
table.setColumnCollapsible("A + B", false);
Tip
You have to call table.setColumnCollapsingAllowed(true);
when you want some columns to be noncollapsible. If you don't make this call, the menu showing the columns won't be rendered. You can use the setColumnCollapsed
method to programmatically collapse a column. For example, if we wanted to collapse the A
column of our previous example, we could do this by calling:
table.setColumnCollapsed("A", true);