To hide a column, simply add visible:false
as an argument within the table declaration.
For example:
columns:[{title: "Test Column", field: "test", sorter:"number", width: 100,visible:false}]
If you want to hide or show multiple columns, you'll first need to identify which columns should be hidden or shown.
A straightforward way to achieve this is by creating an array of Boolean states, like so:
var visibility =[];
visibility.push({col1_Status:true,col2_Status:true,col3_Status:false});
Then, in the table initialization:
columns:[{title: "Test Col1", field: "test1", sorter:"number", width: 100,visible:visibility[0].col1_Status},
{title: "Test Col2", field: "test2", sorter:"number", width: 100,visible:visibility[0].col2_Status},
{title: "Test Col3", field: "test3", sorter:"number", width: 100,visible:visibility[0].col3_Status}]
Once you have your JSON data, you can easily change the visibility based on your requirements.
This method allows for independent operation. You can access multiple array values at any time, modify their status, and update tabulator to hide/show columns accordingly.
You can also apply the same technique with column names by changing the title:
. Just keep in mind that once a column is initialized within the table, its structure cannot be altered. To update the heading (and data), you will need to remove the existing column and replace it with another.
To accomplish this, use:
table.deleteColumn("Column Name Here");
table.addColumn({title:"Name", field:"name"});
I hope this information proves helpful!