In ag-grid I have a table with a structure like this:
| Temperature | ....
-----------|------|------|------|---------
Date | min | avg | max | ....
-----------|------|------|------|---------
2017-03-01 | 19.5 | 20.2 | 22.0 | ....
2017-03-02 | 18.8 | 20.4 | 21.6 | ....
I want to be able to hide the entire Temperature column group and I do it like this:
- get column group by it's name with
columnApi.getColumnGroup(groupId) - get column children with
getChildren() - loop through all elements and hide/show depending on Column visibility state
The hiding part works ok, but when I want to show the columns again, the getColumnGroup method returns a null object, and I cannot set the columns to be visible again. Any ideas?
The entire code (part of an Angular2 component) looks like this:
toggleColumn(groupId: string) {
let groupColumn = this.dataGridOptions.columnApi.getColumnGroup(groupId);
let children = groupColumn.getChildren();
for (let idx = 0; idx < children.length; idx++) {
let colId: string = children[idx].getUniqueId();
let colState = this.dataGridOptions.columnApi.getColumn(colId);
let colVisibility = colState.isVisible();
this.dataGridOptions.columnApi.setColumnVisible(colId, !colVisibility);
}
}