Basic example
The column visibility plug-in for Buttons provides a set of buttons that can be used to easily give the end user the ability to set the visibility of columns. The primary button type for column visibility controls is the colvis type which adds a collection (collection) of buttons, one for each of the columns in the table, with the end user having the ability to toggle these columns.
Multi-column layout
The collection button has a collectionLayout option that can be used to control the layout of the buttons shown in the collection. As the colvis button extends the collection button, this option is also available for the column visibility controls. This example shows a fixed, two column layout. Please see the collectionLayout option in the collection button documentation for the full list of options.
Restore column visibility
The colvisRestore provides a single click button that will restore the table's column visibility to the same as when the DataTable was initialised. This example shows the colvis button collection augmented with the colvisRestore button type through the postfixButtons option to add the restore button to the end of the column visibility collection.
State saving
Button's column visibility module works seamlessly with DataTables' state saving option (stateSave). All you need to do is enable both the column visibility buttons and state saving, as shown in this example. To demonstrate this ability, simple hide a few columns and then refresh the table. The columns you selected to be hidden will remain hidden and the button states will reflect this.
Column groups
When working with column visibility you may wish to present a control to the end use that provides the ability to set various columns to both show and hide at the same time - allowing grouping to occur. The colvisGroup button type provides this ability for Buttons. The show and hide parameters of this button are both column-selector types defining the columns in the table that should be shown or hidden respectively.