Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 887
Andrew Avatar asked Jul 26 '17 17:07

Andrew


People also ask

How do I resize a column to fit the text inside?

Select the column (s) that you want to fit to the text inside them Right click at the top of a selected column, then click "Resize column…" Click "Fit to data, then click, "OK"

How to automatically resize column width in Google Sheets?

To automatically resize column width in Google Sheets to fit text, follow these steps: 1 Select the column (s) that you want to fit to the text inside them 2 Right click at the top of a selected column, then click "Resize column…" 3 Click "Fit to data, then click, "OK" More items...

How do I change the size of Selected Columns in Excel?

Right-click at the top of any of the select columns, click "Resize columns", select "Fit to data", and then click "OK" Or, if you want, you can use the "Fit to data" shortcut, by double-clicking on the barrier between any two of the selected columns (at the top of the columns)

Why are some of the columns wider than others?

Note that some of the columns are wider than others, due to the varying text length in each cell in row 1. Column A has expanded to fit the longest name in that column, as the longest name is longer than the text that is in the header for that particular column.


2 Answers

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;
  }
}
like image 68
Brad Avatar answered Oct 17 '22 16:10

Brad


when you drag the column manually, source is always "uiColumnDragged"

 if (event.source === 'uiColumnDragged') { 
               // your logic here
 }
like image 1
varun Avatar answered Oct 17 '22 18:10

varun