Search code examples
javascriptag-grid

How to tell if column resize is done manually vs. automatically with onColumnResized()?


Before ag-grid v11.0, sizeColumnsToFit() fired with an event that did not pass the parameter 'finished=true'. When a user manually resized a column, the event would pass 'finished=true' once the resize drag was complete. This allowed me to distinguish between a manual and automatic column resize.

As of ag-grid v11.0, sizeColumnsToFit() now fires an event with parameter 'finished=true'. Is there any way to distinguish between this automatic resize and a manual user resize?


Solution

  • The ColumnEvent, from which the ColumnResizedEvent is derived has a "source" property that reads "sizeColumnsToFit" or "uiColumnDragged" and even "autosizeColumns" when a you double click the partition.

    https://www.ag-grid.com/javascript-grid-events/#properties-and-hierarchy

    You should be able to use the source to determine how the event was fired.

    myEventHandler(ev: ColumnResizedEvent) {
      if (ev.source === 'sizeColumnsToFit') {
        do.this;
      } else {
        do.that;
      }
    }