Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ag-grid column grouping resize issue

Tags:

ag-grid

In my developed grid with column grouping, there is white empty space is appear at end when resize the columns. Any Suggestion?[![enter image description here][1]][1]

enter image description here

like image 756
soundar Avatar asked Dec 08 '25 06:12

soundar


2 Answers

You can call sizeColumnsToFit() after columnRowGroupChanged event:

columnRowGroupChanged A row group column was added or removed.

.html template event binding

(columnRowGroupChanged)="groupChanged($event)"

or .ts gridOptions event binding (don't forget to define [gridOptions] in .html)

this.gridOptions:{
    onColumnRowGroupChanged : this.groupChanged.bind(this)
}

handling

groupChanged(params){
    params.api.sizeColumnsToFit();
}

DEMO

like image 106
un.spike Avatar answered Dec 12 '25 09:12

un.spike


Starting from ag-grid 23.1.0, we no longer have to use sizeColumnsToFit. Instead, in column definition, add flex: 1 to the last visible column.

This prevents all annoying jumps and weird grid behavior when resizing columns. In case user enlarge the column, horizontal scrollbar will appear, which is the expected behavior. Please go over your code and change sizeColumnsToFit to the flex solution. Flex also gives you control over relative column sizes, you can read more about it in the docs: https://www.ag-grid.com/javascript-grid-resizing/.

Example:

columnDefs = [{...}
               ...
             {
                headerName: 'HeaderA',
                field: 'name',
                ...
                flex: 1, // Adding this to last column definition
              }]
like image 36
huan feng Avatar answered Dec 12 '25 10:12

huan feng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!