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 colvistype 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 collectionbutton has a collectionLayoutoption that can be used to control the layout of the buttons shown in the collection. As the colvisbutton 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 collectionLayoutoption in the collectionbutton documentation for the full list of options.
Restore column visibility
The colvisRestoreprovides 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 colvisbutton collection augmented with the colvisRestorebutton type through the postfixButtonsoption 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 colvisGroupbutton type provides this ability for Buttons. The showand hideparameters of this button are both column-selectortypes defining the columns in the table that should be shown or hidden respectively.