Column Resizing Feature Guide
Mantine React Table has a built-in column resizing draggable handle feature.
The Column Size features was recently split into its own Guide. View that guide as a prerequisite to this one.
Relevant Table Options
# | Prop Name | Type | Default Value | More Info Links | |
---|---|---|---|---|---|
1 | 'onChange' | 'onEnd' | 'onChange' | MRT Column Resizing Docs | ||
2 | Partial<MRT_ColumnDef<TData>> |
| TanStack Table Core Table Docs | ||
3 | { [key: string]: MRT_ColumnDef<TData> } |
| MRT Display Columns Docs | ||
4 | boolean |
| MRT Column Resizing Docs | ||
5 | 'semantic' | 'grid' | 'semantic' | TODO | ||
6 | OnChangeFn<ColumnSizingState> |
| TanStack Table Column Sizing Docs | ||
7 | OnChangeFn<ColumnSizingInfoState> |
| TanStack Table Column Sizing Docs | ||
Relevant Column Options
Relevant State
# | State Option | Type | Default Value | More Info Links | |
---|---|---|---|---|---|
1 | Record<string, number> | {} | TanStack Table Column Sizing Docs | ||
2 | See TanStack Docs | {} | TanStack Table Column Sizing Docs | ||
Initial Column Sizes
Column sizes will behave differently depending on which layoutMode
you have set.
See the Column Size Guide for more information on layout modes and how to set initial column sizes properly for you use case.
Enable Column Resizing Feature
enableColumnResizing
is the boolean table option that enables the column resizing feature.
You can disable specific columns from being resizable by setting the enableResizing
column option to false in their respective column definition.
Column Resize Mode
The default columnResizeMode
is onChange
(in MRT versions v1.7+), which means that the column resizing will occur immediately as the user drags the column resize handle. If you are running into performance issues because of many other enabled features, you might want to set the columnResizeMode
to onEnd
instead. This will make the column resizing only occur after the user has finished dragging the column resize handle and released their mouse.
First Name | Last Name | Email Address | City | Country | |
---|---|---|---|---|---|
Dylan | Murray | dmurray@yopmail.com | East Daphne | USA | |
Raquel | Kohler | rkholer33@yopmail.com | Columbus | USA | |
Ervin | Reinger | ereinger@mailinator.com | Toronto | Canada | |
Brittany | McCullough | bmccullough44@mailinator.com | Lincoln | USA | |
Branson | Frami | bframi@yopmain.com | New York | USA |
Column Growing
MRT V2 has a new "opposite" behavior in regards to column sizes when column resizing is enabled compared to MRT V2
When column resizing is enabled, by default, a layoutMode of "grid-no-grow"
will be applied internally. This means that columns will have an absolute size and they will NOT grow to fill in the remaining space of the table. You can let columns grow to fill in the remaining space by changing the layoutMode
back to "grid"
or "semantic"
.
Alternatively, if you only want certain columns to grow to fill the remaining space, you can set the grow
column option to true
in their respective column definitions.
This is discussed in more detail in the Column Size Guide.
Column Resize Direction
If you are displaying your table in a RTL (right-to-left) language, you can set the columnResizeDirection
table option to "rtl"
to make the column resize handle appear on the left side of the column instead of the right side. This may behave differently depending on which Emotion or MUI theme settings you have enabled.
If you have already set the proper theme.direction
setting in your MUI theme, then this option will already have been set automatically for you, but you can still override it using the columnResizeDirection
table option.
عملیات | انتخاب | نام | نام خانوادگی | سن |
---|---|---|---|---|
میسی | 26 | |||
پریا | 28 | |||
علی | 33 |
Enable Resizing on Built-in Display Columns
As discussed further in the Display Columns Guide, you can customize the options of the built-in columns that get generated under the hood by MRT by enabling certain features.
Here, we can enable column resizing on the built-in row numbers column by setting the enableResizing
column option to true in the displayColumnDefOptions
table option.
View Extra Storybook Examples