Column Sizing

The width of the columns can be set using a given value through columnDefs or columnState (
see Column Definitions, Updating Column Definitions
and Column State). It is also
possible to let Dash AG Grid calculate the width of the columns with the columnSize property and allow the user to
resize the columns by dragging the top right portion of the column.

Sizing

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.

columnDefs = [
    { "field": "name"},
    { "field": "age" },
    { "field": "address", "resizable": False},
]

The snippet below allows only the Address to be resized by setting resizable=False on the default column
definition and then resizable=True on the Address column.

defaultColDef = {
    "resizable": False,
}
columnDefs = [
    { "field": "name" },
    { "field": "age" },
    { "field": "address", "resizable": True },
]

columnSize property

To set the column size, use the columnSize property, along with columnSizeOptions to customize the columnSize
operation.

Note that columnSize and columnSizeOptions are Dash properties only. You won’t find these properties defined the
same way in the AG Grid documentation.

columnSize takes one of the following:

The following example shows how to make columns adjust to fit either the screen or their contents. With each option, try
resizing the columns (by dragging the column header) and resize the browser width to see how the grid responds.

Autosize

Setting columnSize="autoSize" will auto-size all columns based on its contents. Note that, just like Excel, each
column can also be auto-resized by double-clicking the right side of the header rather than dragging it.

Autosize and Virtualisation

Notes about autosizing and Virtualisation:

Skip header on autosize

By default, the grid will also resize the column to fit the header. If you do not want the headers to be included in
the autosize calculation, set the grid option:

dashGridOptions = {"skipHeaderOnAutoSize": True}
Autosize a subset of columns

Using columnSize="autoSize", it is possible to apply the auto-size to only a subset of columns or to not take into
account the headers when calculating the column size, it is possible to use columnSizeOptions with the following
parameters:

Note that Column Groups are never considered when calculating the column widths.

Size to Fit and Responsive Size to Fit

Setting columnSize="sizeToFit" makes the columns fit the width of the grid. However, unlike "responsiveSizeToFit",
this is only done once when the grid is rendered. If the browser window changes, or the user changes the column width,
the columns will not be continually resized. But it is possible to set again "sizeToFit" to recalculate the width of
the columns when needed, see
example Size to Fit Triggered by Callback Example

Setting columnSize="responsiveSizeToFit" makes the currently visible columns fit the screen. The columns will scale (
growing or shrinking) to fit the available width.

Note that when columnSize="responsiveSizeToFit", the 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.

Skip columns on resize

For both columnSize options, if you don’t want a particular column to be included in the 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 grid.

Set a minimum and maximum width on resize

It is also possible to set minimum and maximum width when calculating the column sizes using columnSizeOptions with
the following parameters:

Example Size to Fit Using Options

This example shows how to set options with "sizeToFit", note the following:

Example Size to Fit Triggered by Callback

This example adds a button so the user can resize the grid. Try changing a column width or the browser window then
hit the “Resize” button.

Shift Resize

If you hold the <kbd>Shift<kbd> key while dragging the resize handle, the column will take space away from the column
adjacent to it. This means the total width for all columns will be constant.

You can also change the default behavior for resizing. To have shift resizing as the default and normal resizing to
happen when the <kbd>Shift<kbd> key is pressed, set the grid option:

dashGridOptions = {"colResizeDefault": 'shift'}

Resize Groups

When you resize a group, it will distribute the extra room to all columns in the group equally. In the example below,
the groups can be resized as follows:

View the CSS classes used for this example

These CSS classes must be added to any *.css file in the assets folder.
See Loading CSS files for more information.

span.legend-box {
    display: inline-block;
    border: 1px solid #aaa;
    height: 15px;
    width: 15px;
    margin-left: 15px;
    margin-right: 5px;
}

.resizable-header {
    background-color: #66c2a5 !important;
}

.fixed-size-header {
    background-color: #e78ac3 !important;
}

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 parameter. Some columns could be set with a regular width parameter, while other columns
would have a flex parameter.

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 parameter does not work with a width parameter in the same column. If you need to provide a
minimum width for a column, you should use flex and the minWidth parameter. 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.

In the example below, note the following:

This second example has flex in all columns. Try changing the browser window size and note how the proportions of the
columns
are maintained.