Customize (Style) Components Guide
One of the strengths of Mantine React Table is that it exposes a majority of all the underlying Mantine component props used to build the table.
Additionally, in one of the sections below, you will learn how to customize and use the Mantine Theme to customize colors, typography, or any other default CSS that is used by Mantine React Table.
Relevant Table Options
All props labeled
mantine...Props
get forwarded to Mantine components. Here is a list of all the props that are exposed in both the root props and column options.Relevant Column Options
Some of the column options expose the same props as above, but on a per column basis.
Mantine Props and Types
Each prop can either be passed as an object or as a callback function where you get access to the underlying
table
instance and any other relevant callback parameters, such as cell
, row
, column
, etc. This lets you easily run conditional logic on the props you pass. Let's take a look at a few examples.Allmantine...Props
props are strongly typed and you should get ts hints as you write them. API docs are available on the Mantine website for each component.
Static Prop Objects
Callback Functions to Dynamically Set Prop Values
Styling Mantine Components
Each
mantine...Prop
has multiple options for you to add styling to the component. You could simply pass className
or style
props to any mantine...Props
prop, but there is also the sx
prop.The SX Prop
Note: Mantine V7 (coming out at the end of 2023) is getting rid of emotion and the sx prop. So MRT V2 is going to have very different advice than down below. Consider using CSS modules with theclassName
prop instead of thesx
prop. Or just using thestyle
prop. Or consider using Tailwind. 🤪
The recommended way to style Mantine components in Mantine React Table will be the
sx
prop throughout this docs site, as it is both the most simple and the most powerful way to style Mantine components. They can work and be as simple as a style
prop, but behind the scenes, they work more like emotion styled-components by using Emotion.Do not worry,
className
and style
props will still work, but let's show off some of the more elegant syntax you can use with the sx
prop.- The
sx
prop can be used just a simply as astyle
prop by default
- The
sx
prop gets easy access to your mantineTheme without you having to call the theme from auseMantineTheme
hook.
- The
sx
prop gives you a much more concise way to add media queries to your styling.
There are many more advantages to using the
sx
prop, but that is all we will discuss in these docs. You can learn more about it the official Mantine Docs.Mantine Theme
Mantine React Table respects your Mantine Theme. If you have already set up Mantine and a global Mantine Theme, you should already be set. But if you have not, you should visit the official Mantine Theming Docs to learn how to set that up.
Customize Theme Just for your Table
Thanks to Mantine allowing you to nest multiple Theme Providers, you can change your Mantine Theme just for the
<MantineReactTable />
component by wrapping a <MantineProvider theme={{...}}>
around just your table. The values in this theme will only effect the <MantineReactTable />
component, and not the rest of your site. It will also inherit values from your global theme, so you do not have to redefine everything again. You can just tweak the values you want to change.Important Theme Values used by Mantine React Table
<MantineReactTable />
will primarily use the following values internally from your Mantine Theme by default:theme.colors[theme.primaryColor[theme.primaryShade]]
- used as the primary color for anything colorful in the table (primary buttons, text inputs, checkboxes, dragging borders, etc.)theme.colors.gray[3, 7, 8]
- used for some borderstheme.colors.dark[7, 8]
- used as the default backgroundColor for the entire table in dark modetheme.white
- used as the default backgroundColor for the entire table in light modetheme.black
- used for some box shadows
If you want to change some of the colors used by specific components within the table, remember that you can use the
sx
prop in any of the mantine...Props
to override the default styles.Custom Mantine Theme Example
A common use case for this could be if you want to switch your primary and secondary colors, just for this table. Let's take a look at an example that does that, along with some other styling tweaks, so that we can make an ugly table.
First Name | Last Name | Address | City | State | |
---|---|---|---|---|---|
Dylan | Murray | 261 Erdman Ford | East Daphne | Kentucky | |
Raquel | Kohler | 769 Dominic Grove | Columbus | Ohio | |
Ervin | Reinger | 566 Brakus Inlet | South Linda | West Virginia | |
Brittany | McCullough | 722 Emie Stream | Lincoln | Nebraska | |
Branson | Frami | 32188 Larkin Turnpike | Charleston | South Carolina |
1-5 of 5
Customize Table Paper Styling
You can customize both the props and the styles of the internal
<Paper />
component that wraps the table by passing in a mantinePaperProps
prop. This is useful if you want to change the elevation of the paper, or add a border radius, or any other styling you want to do to the paper.Customize Table Body, Rows, Columns, and Cells
Here are a few examples of how you can customize the table body, rows, columns, and cells.
Stripe Rows Example
Mantine's Table component has a
striped
prop that you can use to stripe the rows.But if you want to stripe the rows yourself, you can do something like this:
Stripe Columns Example
Similarly, if you want to stripe the columns, you can do something like this:
ID | First Name | Middle Name | Last Name | Address | City | State |
---|---|---|---|---|---|---|
1 | Dylan | Sprouse | Murray | 261 Erdman Ford | East Daphne | Kentucky |
2 | Raquel | Hakeem | Kohler | 769 Dominic Grove | Columbus | Ohio |
3 | Ervin | Kris | Reinger | 566 Brakus Inlet | South Linda | West Virginia |
4 | Brittany | Kathryn | McCullough | 722 Emie Stream | Lincoln | Nebraska |
5 | Branson | John | Frami | 32188 Larkin Turnpike | Charleston | South Carolina |
1-5 of 5