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
function column().visible()
- Description:
Get the visibility of the selected column.
- Returns:
true
if the column is visible,false
if it is not.
function column().visible( show [, redrawCalculations ] )
- Description:
Set the visibility of the selected column.
- Parameters:
Name Type Optional 1 show
No Specify if the column should be visible (
true
) or not (false
).2 redrawCalculations
Yes - default:true Indicate if DataTables should recalculate the column layout (
true
- default) or not (false
). Typically this would be left as the default value, but it can be useful to disable when using the method in a loop - so the calculations are performed on every call as they can hamper performance.- Returns:
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.