Column Size Feature Guide
Mantine React Table lets you easily change the default widths (sizes) of columns.
Relevant Table Options
# | Prop Name | Type | Default Value | More Info Links | |
---|---|---|---|---|---|
1 | Partial<MRT_ColumnDef<TData>> |
| TanStack Table Core Table Docs | ||
2 | { [key: string]: MRT_ColumnDef<TData> } |
| MRT Display Columns Docs | ||
3 | 'semantic' | 'grid' | 'semantic' | TODO | ||
Relevant Column Options
Relevant State
# | State Option | Type | Default Value | More Info Links | |
---|---|---|---|---|---|
1 | Record<string, number> | {} | TanStack Table Column Sizing Docs | ||
Layout Modes
Mantine React Table has 3 layout modes that affect how columns styles are applied internally. Depending on which features you enable, the layoutMode
table option will automatically change to the appropriate value, though you can override it with your own value if you want.
"semantic"
(default with default features) - uses default css styles that come with<table>
,<tr>
,<td>
, etc. elements."grid"
(default when virtualization is enabled) - uses CSS Grid and Flexbox styles instead of default styles."grid-no-grow"
(default when column resizing is enabled) - uses CSS Grid and Flexbox styles, but also setsflex-grow: 0
on all columns and adds an empty "spacer" column to the end of the table to fill the potential remaining space.
If you want your columns to have an absolute width, you can use the "grid-no-grow"
layout mode and set the size
option on each column.
Column Size
You can change the width of any column by setting its size
option on the column definition. There are minSize
and maxSize
column options available to enforce limits during resizing events.
The size
, minSize
, and maxSize
do not take in any CSS width unit. They are only numbers that represent the width of the column in pixels.
Column Grow
You can also set grow
properties on the column definitions when using layoutMode "grid-no-grow"
or "grid"
.
If the layout mode of your table is "grid"
and you set grow: false
on a column, that column will have a fixed size and will not grow to fill in the remaining space of the table.
If the layout mode of your table is "grid-no-grow"
and you set grow: true
on a column, that column will grow to fill in the remaining space of the table.
If the layout mode of your table is "grid-no-grow"
and you set grow: 1
on one column, and grow: 2
on another column, the first column will grow to fill in 1/3 of the remaining space of the table, and the second column will grow to fill in 2/3 of the remaining space of the table.
If the layout mode of your table is "semantic"
, the grow
column option will have no effect, but columns will size themselves to fit their own content better than the other layout modes.
But I Want My Columns to Have a Percentage Width
Mantine React Table is not designed to use percentage column widths well by default. This is because having horizontal scrollbars on tables is both a very common use case, and usually the best way to ensure that the actual content of the cells in each column is visible and not cutoff or wrapped excessively.
If you disagree with that, that's fair, and you're not out of luck. Mantine React Table exposes all mantine props, so if you really want to, you can add whatever CSS you want to achieve your own custom column widths behavior. This is not recommended by the maintainer, but some developers have found it useful to set all column sizes and minSizes to a very small number like 1
, 1.5
, 2
, ect., and then use either layoutMode: "semantic"
or layoutMode: "grid"
. This makes the columns act more like they are using percentage widths, up until a certain point. If you really need to never have a horizontal scrollbar, you can edit the mantineTableContainerProps.style
styles to set overflowX: "hidden"
. Be very careful with this though, as this could cause your table to be unusable on smaller screens.
If the above still does not get you to where you need to be, mantineTableHeadCellProps.style
, mantineTableBodyCellProps.style
, and mantineTableFooterCellProps.style
and more are all exposed and available to you to override with whatever custom CSS that you need. Just be aware that non of the built-in TanStack Table size APIs will be accurate anymore.
Side Note: Just Make Your Scrollbars Prettier
Making your scrollbars look better (especially on Windows and Linux) can go a long way to not letting a horizontal scrollbar ruin the look of your table.
Here's what this docs site uses in its global CSS to make scrollbars to more like the default Mac OS scrollbars for everyone:
Default Column
By default, columns will have the following size properties defined:
You can modify the default column widths by setting the defaultColumn
table option on the table.
Change Sizes of 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.
View Extra Storybook Examples