How to auto resize all columns, including the auto group column ?
The following code only resizes standard columns and not the auto group column as this.gridColumnApi.getAllColumns()
doesn't return the auto group column :
autoSizeAllColumns() {
const allColumnIds = this.gridColumnApi.getAllColumns().map(c => c.colId)
this.gridColumnApi.autoSizeColumns(allColumnIds)
},
Auto-Size Columns Just like Excel, each column can be 'auto resized' by double clicking the right side of the header rather than dragging it. When you do this, the grid will work out the best width to fit the contents of the cells in the column.
To group rows by a particular column, enable the rowGroup column property as shown below: const gridOptions = { columnDefs: [ { field: 'country', rowGroup: true, hide: true }, { field: 'year', rowGroup: true, hide: true }, { field: 'sport' }, { field: 'total' } ], // other grid options ... }
The Multiple Group Columns display type adds an Auto Group Column for each row group to the grid. To change the default configurations of these group columns, use the autoGroupColumnDef grid option as shown below: const autoGroupColumnDef = { headerValueGetter: params => `${params. colDef.
I was able to size and autosize the autogroup column directly by using the colID (which I learned is 'ag-Grid-AutoColumn').
To size it specifically:
onGridReady:function(params)
{
params.columnApi.setColumnWidth('ag-Grid-AutoColumn', 250);
}
To autosize:
onFirstDataRendered:function(params)
{
params.columnApi.autoSizeColumn('ag-Grid-AutoColumn');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With