I have several ag-grids in my code and the "setColumnDefs" is working for all the grids, however when I am trying to create a new grid, I am getting the error: Cannot read property 'setColumnDefs' of undefined. I don't know what I'm doing wrong. It seems to work for other ag-grids.
vm.newGrid = {
enableSorting: true,
enableColResize: true
};
var newGridColumns = [
{
headerName: 'DATA',
field: 'data',
}, {
headerName: 'PERCENT',
field: 'percent'
}
];
vm.newGrid.api.setColumnDefs(newGridColumns);
you need to wait for the grid to be initialised before the api is ready.
so you have two choices: a) put the grids directly onto the gridOptions
vm.newGrid = {
enableSorting: true,
enableColResize: true,
columnDefs: [
{
headerName: 'DATA',
field: 'data',
}, {
headerName: 'PERCENT',
field: 'percent'
}
]
};
or b) wait for the grid to be initialised
vm.newGrid = {
enableSorting: true,
enableColResize: true,
onGridReady: function(params) {
params.api.setColumnDefs(newGridColumns);
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With