How can I determine if a column is being resized manually or automatically using onColumnResized ()?
Before ag-grid v11.0, sizeColumnsToFit () is fired with an event that did not pass the 'finished = true' parameter. When the user manually resizes the column, the event will pass "finished = true" after the size has been dragged. This allowed me to differentiate between manual and automatic column sizes.
As of ag-grid v11.0, sizeColumnsToFit () now fires an event with the 'finished = true' parameter. Is there a way to differentiate between this auto size and user manual size?
source to share
The ColumnEvent from which the ColumnResizedEvent originates has a "source" property that reads "sizeColumnsToFit" or "uiColumnDragged" and even "autosizeColumns" when you double-click on a section.
https://www.ag-grid.com/javascript-grid-events/#properties-and-hierarchy
You should be able to use the source to determine how the event happened.
myEventHandler(ev: ColumnResizedEvent) {
if (ev.source === 'sizeColumnsToFit') {
do.this;
} else {
do.that;
}
}
source to share
Code added since 10
colsToFireEventFor.forEach( (column: Column) => {
let event: ColumnResizedEvent = {
type: Events.EVENT_COLUMN_RESIZED,
column: column,
columns: [column],
finished: true,
api: this.gridApi,
columnApi: this.columnApi
};
this.eventService.dispatchEvent(event);
});
You can try to change the complete comment of the comment: property is true or just use version 10.0 where this func looks like this:
colsToFireEventFor.forEach( (column: Column) => {
let event = new ColumnChangeEvent(Events.EVENT_COLUMN_RESIZED).withColumn(column);
this.eventService.dispatchEvent(Events.EVENT_COLUMN_RESIZED, event);
});
source to share