{hero}

columns().visible()

Since: DataTables 1.10

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

function columns().visible()

Description:

Get the visibility of the selected columns.

Returns:

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.

function columns().visible( show [, redrawCalculations ] )

Description:

Set the visibility of the selected columns.

Parameters:
Returns:

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.