React Data GridColumn Sizing

All columns can be resized by dragging the top right portion of the column.


Column resizing is enabled by default for all columns. To control resizing for individual columns, set the boolean resizable property in the column definitions.

The snippet below allows all columns except Address to be resized.

const [columnDefs, setColumnDefs] = useState([
    { field: 'name' },
    { field: 'age' },
    { field: 'address', resizable: false },

<AgGridReact columnDefs={columnDefs} />

The snippet below shows how to only allow the Address column to be resized by setting resizable=false on the default column definition and then resizable=true on the Address column.

const defaultColDef = useMemo(() => { 
	return {
        resizable: false,
}, []);
const [columnDefs, setColumnDefs] = useState([
    { field: 'name' },
    { field: 'age' },
    { field: 'address', resizable: true },


Column Flex

It's often required that one or more columns fill the entire available space in the grid. For this scenario, it is possible to use the flex config. Some columns could be set with a regular width config, while other columns would have a flex config.

Flex sizing works by dividing the remaining space in the grid among all flex columns in proportion to their flex value. For example, suppose the grid has a total width of 450px and it has three columns: the first with width: 150; the second with flex: 1; and third with flex: 2. The first column will be 150px wide, leaving 300px remaining. The column with flex: 2 has twice the size with flex: 1. So final sizes will be: 150px, 100px, 200px.

The flex config does not work with a width config in the same column. If you need to provide a minimum width for a column, you should use flex and the minWidth config. Flex will also take maxWidth into account.

If you manually resize a column with flex either via the API or by dragging the resize handle, flex will automatically be disabled for that column.

The example below shows flex in action. Things to note are as follows:

  • Column A is fixed size. You can resize it with the drag handle and the other two columns will adjust to fill the available space
  • Column B has flex: 2, minWidth: 200 and maxWidth: 350, so it should be constrained to this max/min width.
  • Column C has flex: 1 so should be half the size of column B, unless column B is being constrained by its minWidth/maxWidth rules, in which case it should take up the remaining available space.

Auto-Sizing Columns

Columns can be auto-sized in two main ways:

  1. Auto-size columns to fit grid - The columns will scale to fit the available grid width (or a provided width if desired).
  2. Auto-size columns to fit cell contents - The columns will resize to fit their visible cell contents.

Auto-Size Columns to Fit Grid

Columns can be resized to fit the width of the grid. The columns will scale (growing or shrinking) to fit the available width.

Provide the grid option autoSizeStrategy to size the columns to fit when the grid is loaded. This can either be set to size to the actual grid width (type = 'fitGridWidth'), or to a fixed width that is provided (type = 'fitProvidedWidth').

const autoSizeStrategy = {
    type: 'fitGridWidth',
    defaultMinWidth: 100,
    columnLimits: [
            colId: 'country',
            minWidth: 900

<AgGridReact autoSizeStrategy={autoSizeStrategy} />

The columns can also be sized on demand via api.sizeColumnsToFit(params).

If you don't want a particular column to be included in the auto-resize, then set the column definition suppressSizeToFit=true. This is helpful if, for example, you want the first column to remain fixed width, but all other columns to fill the width of the table.

The grid calculates new column widths while maintaining the ratio of the column default widths. So for example if Column A has a default size twice as wide as Column B, then after the sizing is performed, Column A will still be twice the size of Column B, assuming no column min-width or max-width constraints are violated.

Column default widths, rather than current widths, are used while calculating the new widths. This ensures the result is deterministic and does not depend on any column resizing the user may have manually done.

A parameters object can be provided with minimum and maximum widths, either for all columns or for specific columns, to further restrain the column's resulting width from that function call. These widths will not exceed the column's defined minimum and maximum widths.

For example assuming a grid with three columns, the algorithm will be as follows:

scale = availableWidth / (w1 + w2 + w3)

w1 = round(w1 * scale)

w2 = round(w2 * scale)

w3 = totalGridWidth - (w1 + w2)

Assuming the grid is 1,200 pixels wide and the columns have default widths of 50, 120 and 300, then the calculation is as follows:

availableWidth = 1,198 (available width is typically smaller as the grid typically has left and right borders)

scale = 1198 / (50 + 120 + 300) = 2.54

col1 = round(50 * 2.54) = 127

col2 = round(120 * 2.54) = 306

col3 = 1198 - (127 + 306) = 765 (the last column gets any space that's left, which ensures all space is used, so no rounding issues)

Auto-Size Columns to Fit Cell Contents

Columns can be resized to fit the contents of the cells. The example below demonstrates the use of autoSizeStrategy to size the columns by default. The example button can restore this sizing by using the API if the columns are first resized by dragging the resize handle.

Provide the grid option autoSizeStrategy with type = 'fitCellContents' to size the columns to fit their content when the first data is rendered in the grid.

const autoSizeStrategy = {
    type: 'fitCellContents'

<AgGridReact autoSizeStrategy={autoSizeStrategy} />