{hero}

colvis

Since: Buttons 1.0.0

A button collection that provides column visibility control.
Please note - this property requires the Buttons extension for DataTables.

Description

This button will create a collection button that when activated will show a list of the columns in the table and provide the end user with the ability to toggle column visibility to suit their own requirements.

Options

This button can have the following options set in its configuration object to customise its actions and display, in addition to those options which are available for all buttons (e.g. buttons.buttons.text):

Examples

DataTables initialisation: Show the colvis button with default options:

new DataTable('#myTable', {
	layout: {
		topStart: {
			buttons: ['colvis']
		}
	}
});

Show the colvis button, but do not include the first column in the list of columns:

new DataTable('#myTable', {
	layout: {
		topStart: {
			buttons: [
				{
					extend: 'colvis',
					columns: 'th:nth-child(n+2)'
				}
			]
		}
	}
});

Customisation of the button text for the individual columns:

new DataTable('#myTable', {
	layout: {
		topStart: {
			buttons: [
				{
					extend: 'colvis',
					columnText: function (dt, idx, title) {
						return idx + 1 + ': ' + title;
					}
				}
			]
		}
	}
});