column().visible()
Get / set the visibility of a single selected column.
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 a single column to be changed on-the-fly, or the visibility state of a column to be read.
Types
column().visible()
Get the visibility of the selected column.
Returns:
boolean``true
if the column is visible, false
if it is not.
column().visible( show [, redrawCalculations ] )
Set the visibility of the selected column.
Parameters:
Name | Type | Optional | |
---|---|---|---|
1 | show | No | |
Specify if the column should be visible ( | |||
2 | redrawCalculations | Yes - default:true | |
Indicate if DataTables should recalculate the column layout ( |
Returns:
DataTables.Api
DataTables API instance with selected column in the result set.
Examples
Get the visibility status of column index 0:
var table = new DataTable('#myTable');
alert(
'Column index 0 is ' +
(table.column(0).visible() === true ? 'visible' : 'not visible')
);
Hide the first column in the table:
var table = new DataTable('#myTable');
table.column(0).visible(false);
Hide multiple columns using redrawCalculations
to improve performance:
var table = new DataTable('#myTable');
for (var i = 0; i < 4; i++) {
table.column(i).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.