colvis
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
):
Name | Type | Default |
---|---|---|
action | ||
Show the collection to control column visibility. | ||
className | buttons-collection buttons-colvis | |
The button's class name. See | ||
columnText Since: 1.3.0 | undefined | |
Callback function that provides the ability to modify or replace the text used for each button in the list. This function is executed once for each button. It accepts three parameters:
The return value is a | ||
columns | undefined | |
Columns selector that defines the columns to include in the column visibility button set. By default this is | ||
text | Column visibility | |
The button's display text. The text can be configured using this option (see |
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;
}
}
]
}
}
});