according to documentation:
gridReady
ag-Grid has initialised. The name 'ready' was influenced by the authors time programming the Commodore 64. Use this event if, for example, you need to use the grid's API to fix the columns to size.
so I added auto sizing logic in there:
onGridReady: e => {
var allColumnIds = [];
columndefs.forEach(function (columnDef) {
allColumnIds.push(columnDef.field);
});
e.columnApi.autoSizeColumns(allColumnIds);
console.log('the grid is now ready', e)
}
this does not work well I think because this event fires before data is bound. So grid doesn't have enough information on how to auto size the columns. I am thinking about maybe calling this logic on model updated ?
if your data is set on the gridOptions, then the above is true.
however if you are using a framework to bind the data (eg passing it in as an Angular bound property) then it's up to the framework in what order it creates the grid and binds the properties.
got it,
so in the latter scenario which event can i use to call column autosize? seems whatever i try calls it too early because columns are not sized properly until i do it one more time manually by clicking a button after data has loaded.
depends on your setup. something you can try is putting it in a timeout. eg:
onGridReady: e => {
setTimeout( () => {
e.columnApi.autoSizeAllColumns();
}, 0);
}
Most helpful comment
got it,
so in the latter scenario which event can i use to call column autosize? seems whatever i try calls it too early because columns are not sized properly until i do it one more time manually by clicking a button after data has loaded.