I have an angular project that uses Ag-Grid and here is my problem.
I thing that I have tried all that is in my hand but I'm not able to make it work... My code needs to add and remove some Columns dynamically, and in the documentation I saw that setColumnDefs from the GridApi was a good idea to try it.
I don't know If I'm doing something wrong, but I tried to follow the docs as much as I can.
This is the method that updates the columns definitions (it doesn't work)
updateColumnsMode(): void {
if(!this.showAdvancedColumns) {
this.gridOptions
.api!
.setColumnDefs(this.buildColumns(this.advancedColumnsName)));
} else {
this.gridOptions
.api!
.setColumnDefs(this.buildColumns(this.normalColumnsName)));
}
}
My grid Options
gridOptions: GridOptions = {
rowData: this.rowData,
columnDefs: this.buildColumns(this.normalColumnsName),
onGridReady: (event:any) => console.log("Grid working!"),
}
And the api initialization
onGridReady(params: any) {
this.gridApi = params.api;
this.gridColumnApi = params.columnApi;
}
And if it could be relevant, the method where I build the columns
buildColumns(columnsToBuild: String[]): ColDef[] {
return columnsToBuild.map((column):any => {
return { "field": column, sortable: true, filter: true }
});
}
The columnsToBuild is jut an array of String.
I really need help with this guys.