Setting default columns hidden with the DataTable ColVis extension

How can I provide a list of columns that I want to hide when loading a table through the ColVis extension?

Also, is there a way to get a list of columns that are currently visible / hidden?

+5
source share
2 answers

Specify visible columns

You can set the visibility with the parameters or to specific columns along with the parameter to set the visibility of the columns. columnDefs columnDefs columns columnDefs columns.visible

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

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

See this jsFiddle for a demo.

Get a list of visible columns

, columns().visible().

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

jsFiddle .

+9

ColVis . .Datatable().

/ , -

var length = myTable.columns().nodes().length,
    result = [];
for(var i=0;i<length;i++){
    result.push(myTable.column(i).visible());
}
console.log(result);

http://jsfiddle.net/dhirajbodicherla/189Lp6u6/25/

0

Source: https://habr.com/ru/post/1598134/


All Articles