As what has been suggested elsewhere,
setColumnDefs is not working for some ag-grids
How to initialize ag-grid api in angular2 application
I have already initialized the gridOptions in my class constructor. But when I tried to setColumnDefs, it still gave me error:
TypeError: Cannot read property 'setColumnDefs' of undefined
What else am I missing here?
export class ConfigurationComponent implements OnInit {
constructor(
private configurationService: ConfigurationService,
)
{
this.gridOptions = {
enableSorting: false,
rowData: this.tableData,
columnDefs: this.tableColumns,
onGridReady: () => {
this.gridOptions.api.sizeColumnsToFit();
this.gridOptions.api.setColumnDefs(this.tableColumns);
alert(this.gridOptions.api);
}
}
}
tableData: string[] = [];
tableList: string[] = [];
tableName: string;
tableColumns: [{headerName: string, field: string}] = [{headerName: "", field: ""}];
tableRecord: {};
gridOptions: GridOptions;
ngOnInit() {
this.retrieveTableList();
}
retrieveTableList(){
/*blah blah*/
}
retrieveTableData(){
/*blah blah*/
this.configurationService.retrieveTableData(this.schemaFullname, this.tableName).subscribe(data => {
/* GETTING tableColumn HERE from the service*/
this.gridOptions.api.setColumnDefs(this.tableColumns);
}, error => {
console.error(error);
this.alertService.error("Get table data error", "No table data retrieved from data source for " + this.tableName);
})
}
}