Setting default columns hidden using DataTable ColVis extension

Specify visible columns

You can set visibility with columnDefs or columns options to target specific columns along with columns.visible option to set column visibility.

For example, to hide a second column initially, use the following options:

var table = $('#example').DataTable({
    'columnDefs': [
       { targets: 1, visible: false }
    ]
});

See this jsFiddle for demonstration.

Get a list of visible columns

You can get a list of visible columns bu using columns().visible() method.

var colVisible = table.columns().visible();

See this jsFiddle for demonstration.

Tags:

Datatables