How to set default min and max column width in ag-grid
Asked Answered
M

4

6

I am using ag-grid library for advanced data grid.

In ag-grid library, I can define "minWidth" and "maxWidth" attributes in "columnDefs" to set minimum and maximum width for particular column.

But is there any option to set default min and max width for each column to set re-sizing boundaries for columns?

Mignonne answered 22/4, 2016 at 23:42 Comment(0)
C
1

Have a single function in the scope to define column widths and heights.

$scope.commonWidth = function() {
      return 50 + calcDynWidth();    //Dummy function
}


$scope.gridOptions = {
   columnDefs: [
      {headerName: 'Name', minWidth: $scope.commonWidth()}
   ]
}
Carnivorous answered 26/4, 2016 at 17:53 Comment(2)
Through columnDef, I have to define minWidth and maxWidth attributes for each column. I am looking for a way where I can configure and set min/max width which will be applicable for all the columns.Mignonne
I believe this way you can do it in one place. The other easiest way is to change the source.Carnivorous
S
1

For AG Grid React, giving the maxWidth and minWidth in the column definition worked for me.

For eg:

const defaultColDef = {
  minWidth:200,
  maxWidth:400,
}

Here i'm setting the values as 200 and 400 which can be replaced by any variable value according to your use-case.

The same can be applied to individual column definitions also.

Seedling answered 9/4, 2024 at 8:27 Comment(0)
I
0

There is the auto-size-strategy which lets you define the default behavior for the grid which you can use like this.

const gridOptions = {
    autoSizeStrategy: {
        type: 'fitCellContents'
    },

    // other grid options ...
}

The next two Entries in the Docs might also be interesting. (autoSizeColumns, autoSizeAllColumns)

Illconditioned answered 9/4, 2024 at 8:36 Comment(0)
D
-1

This works for me:

<ag-grid-angular
      [defaultColDef]="defaultColDef"



public defaultColDef: ColDef = {
    wrapHeaderText: true,
    autoHeaderHeight: true,
    minWidth: 100,
    floatingFilterComponent: 'myCustomFilter',
    filter: 'myCustomFilter',
    type: ['defaultColumn'],
    sortable: true,
  };

The minWith property is the key

Diaphoresis answered 31/3, 2023 at 12:10 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.