columnVisibility

Since: Buttons 1.0.0

A single button that controls the visibility of one or more columns. Please note - this property requires the Buttons extension for DataTables.

Description

This button type creates a single button that can control the visibility of one or more columns in a DataTale (its counterpart b-buttons columnsVisibility will be expanded to a single button for each column). This provides the ability to have show all / hide all buttons that control all of the table's columns or a subset of those columns.

For multiple columns, the button should be given a title using the buttons.buttons.text option, which can also be used for a single column control button, although it will automatically be given the column's title text if not otherwise supplied.

Options

This button can have the following options set in its configuration object to customise its actions and display:

Examples

DataTables initialisation: Show all / hide all buttons:

$('#myTable').DataTable( {
	buttons: [
		{
			extend: 'columnVisibility',
			text: 'Show all',
			visibility: true
		},
		{
			extend: 'columnVisibility',
			text: 'Hide all',
			visibility: false
		}
	]
} );

Direct initialisation: Show / hide columns with the class secondary:

new $.fn.dataTable.Buttons( table, {
	buttons: [
		{
			extend: 'columnVisibility',
			text: 'Show secondary',
			visibility: true,
			columns: '.secondary'
		},
		{
			extend: 'columnVisibility',
			text: 'Hide secondary',
			visibility: false,
			columns: '.secondary'
		}
	]
} );