I'm using ag-grid for representing some data in UI. I have a problem with auto-sizing columns after setting row data using RxJS.
I have a code which set the data:
this.accountingStoreService.getPurchaseOrders().subscribe(
purchaseOrders => {
this.gridApi.setRowData(purchaseOrders);
}
);
How can I call autoSize to make sure that all data was rendered? I was trying to use processRowPostCreate but it also doesn't work without setting timeout:
this.gridOptions = {
rowData: this.purchaseOrders,
processRowPostCreate: (params) => {
this.generateRowEvents(params);
},
...
}
public generateRowEvents(params) {
params.addRenderedRowListener('load', this.autoSizeColumns());
}
public autoSizeColumns() {
const allColumnIds = [];
this.gridColumnApi.getAllColumns().forEach(function (column) {
if (!column.colDef.suppressSizeToFit) {
allColumnIds.push(column.colId);
}
});
setTimeout(() => {
this.gridColumnApi.autoSizeColumns(allColumnIds);
}, 300);
}
But this implementation sometimes works incorrectly.
Is it possible to implement it without using any timeouts or something like that?