columns().visible()
Get / set the visibility of the selected columns.
Description
Showing and hiding columns in a DataTable can be quite handy, particularly when showing tables with a large information density. This method allows the visibility of columns to be changed on-the-fly, or the visibility state of the columns to be read.
Types
columns().visible()
Get the visibility of the selected columns.
Returns:
DataTables.Api
API instance with the result set containing a boolean value for each column the selector matched. The boolean values indicate: true
if the column is visible, false
if it is not.
columns().visible( show [, redrawCalculations ] )
Set the visibility of the selected columns.
Parameters:
Name | Type | Optional | |
---|---|---|---|
1 | show | No | |
Specify if the columns should be visible ( | |||
2 | redrawCalculations | Yes - default:true | |
Indicate if DataTables should recalculate the column layout ( |
Returns:
DataTables.Api
DataTables API instance with selected columns in the result set.
Examples
Set column visibility for two columns:
var table = new DataTable('#myTable');
// Hide two columns
table.columns([1, 2]).visible(false);
alert(
"Table's column visibility are set to: " +
table
.columns()
.visible()
.join(', ')
);
Hide all columns with a class of '.detail':
var table = new DataTable('#myTable');
table.columns('.detail').visible(false);
Hide multiple columns using redrawCalculations
to improve performance:
var table = new DataTable('#myTable');
table.columns([0, 1, 2, 3]).visible(false, false);
table.columns.adjust().draw(false); // adjust column sizing and redraw
Related
The following options are directly related and may also be useful in your application development.