MRT logoMaterial React Table

Legacy V1 Docs
On This Page

    Customize (Style) Components Guide

    One of the strengths of Material React Table is that it exposes a majority of all the underlying Material UI component props used to build the table.

    Additionally, in one of the sections below, you will learn how to customize and use a Material UI Theme to customize colors, typography, or any other default CSS that is used by Material React Table.

    Relevant Props

    All props labeled mui...Props get forwarded to Material UI components. Here is a list of all the props that are exposed in both the root props and column options.

    1
    ToolbarProps | ({ table }) => ToolbarProps
    Material UI Toolbar Props
    2
    IconButtonProps | ({ table }) => IconButtonProps
    Material UI IconButton Props
    3
    IconButtonProps | ({ row, table }) => IconButtonProps
    Material UI IconButton Props
    4
    LinearProgressProps | ({ isTopToolbar, table }) => LinearProgressProps
    Material UI LinearProgress Props
    5
    TextFieldProps | ({ table }) => TextFieldProps
    Material UI TextField Props
    6
    CheckboxProps | ({ table }) => CheckboxProps
    Material UI Checkbox Props
    7
    CheckboxProps | ({ row, table }) => CheckboxProps
    Material UI Checkbox Props
    8
    ButtonProps | ({ cell, column, row, table }) => ButtonProps
    Material UI Button Props
    9
    TextFieldProps | ({ cell, column, row, table }) => TextFieldProps
    Material UI TextField Props
    10
    TableCellProps | ({ cell, column, row, table }) => TableCellProps
    Material UI TableCell Props
    11
    SkeletonProps | ({ cell, column, row, table }) => SkeletonProps
    Material UI Skeleton Props
    12
    TableBodyProps | ({ table }) => TableBodyProps
    Material UI TableBody Props
    13
    IconButtonProps | ({ row, table }) => IconButtonProps
    Material UI IconButton Props
    14
    TableRowProps | ({ isDetailPanel, row, table }) => TableRowProps
    { hover: true }
    Material UI TableRow Props
    15
    TableContainerProps | ({ table }) => TableContainerProps
    Material UI TableContainer Props
    16
    TableCellProps | ({ row, table }) => TableCellProps
    Material UI TableCell Props
    17
    TableCellProps| ({table, column}) => TableCellProps
    Material UI TableCell Props
    18
    TableFooterProps | ({ table }) => TableFooterProps);
    Material UI TableFooter Props
    19
    TableRowProps | ({table, footerGroup}) => TableRowProps
    Material UI TableRow Props
    20
    IconButtonProps | (({table, column}) => IconButtonProps);
    Material UI IconButton Props
    21
    IconButtonProps | ({table, column}) => IconButtonProps
    Material UI IconButton Props
    22
    TextFieldProps | ({ table, column, rangeFilterIndex}) => TextFieldProps
    Material UI TextField Props
    23
    TableCellProps | ({ table, column}) => TableCellProps
    Material UI TableCell Props
    24
    TableHeadProps | ({ table }) => TableHeadProps
    Material UI TableHead Props
    25
    TableRowProps | ({ table, headerGroup}) => TableRowProps
    Material UI TableRow Props
    26
    Partial<TablePaginationProps> | ({ table }) => Partial<TablePaginationProps>
    Material UI TablePagination Props
    27
    PaperProps | ({ table }} => PaperProps
    Material UI Paper API Docs
    28
    TableProps
    Material UI TableProps API Docs
    29
    ChipProps| ({ table }} => ChipProps
    Material UI Chip Props
    30
    AlertProps | ({ table }) => AlertProps
    Material UI Alert Props
    31
    ToolbarProps | ({ table }) => ToolbarProps
    Material UI Toolbar Props

    Relevant Column Options

    Some of the column options expose the same props as above, but on a per column basis.

    1
    ButtonProps | ({ cell, column, row, table }) => ButtonProps
    Material UI Button API
    2
    TextFieldProps | ({ cell, column, row, table }) => TextFieldProps
    Material UI TextField API
    3
    TableCellProps | ({ cell, table }) => TableCellProps
    Material UI TableCell API
    4
    TableCellProps | ({ column, table }) => TableCellProps
    Material UI TableCell API
    5
    IconButtonProps | ({ column, table }) => IconButtonProps
    Material UI IconButton API
    6
    TextFieldProps | ({ column, rangeFilterIndex, table }) => TextFieldProps
    Material UI TextField Props
    7
    TableCellProps | ({ column, table }) => TableCellProps
    Material UI TableCell API

    Material UI 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.

    All mui...Props props are strongly typed and you should get ts hints as you write them. API docs are available on the Material UI website for each component.

    Static Prop Objects

    <MaterialReactTable
    columns={columns}
    data={data}
    enableRowSelection
    //passing the static object variant if no dynamic logic is needed
    muiSelectCheckboxProps={{
    color: 'secondary', //makes all checkboxes use the secondary color
    }}
    />

    Callback Functions to Dynamically Set Prop Values

    <MaterialReactTable
    columns={columns}
    data={data}
    enableRowSelection
    //passing the callback function variant. (You should get type hints for all the callback parameters available)
    muiSelectCheckboxProps={({ row }) => ({
    color: 'secondary',
    disabled: row.original.isAccountLocked, //access the row data to determine if the checkbox should be disabled
    })}
    />

    Styling Material UI Components

    Each mui...Prop has multiple options for you to add styling to the component. You could simply pass className or style props to any mui...Props prop, but there is also the sx prop...which totally rocks!

    Hint: You should just use the sx prop for all styling instead of className or style props.

    The SX Prop

    The recommended way to style Material UI components in Material 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 Material UI components as of Material UI V5. They can work and be as simple as a style prop, but behind the scenes, they work more like emotion styled-components by using mui/system.

    Don't 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.

    1. The sx prop can be used just a simply as a style prop by default

    <MaterialReactTable
    columns={columns}
    data={data}
    muiTableHeadCellProps={{
    //simple styling with the `sx` prop, works just like a style prop in this example
    sx: {
    fontWeight: 'normal',
    fontSize: '14px',
    },
    }}
    />
    1. The sx prop gets easy access to your muiTheme without you having to call the theme from a useTheme hook.

    <MaterialReactTable
    columns={columns}
    data={data}
    muiTableHeadCellProps={{
    //no useTheme hook needed, just use the `sx` prop with the theme callback
    sx: (theme) => ({
    color: theme.palette.text.secondary,
    }),
    }}
    />
    1. The sx prop gives you a much more concise way to add media queries to your styling.

    <MaterialReactTable
    columns={columns}
    data={data}
    muiTableHeadCellProps={{
    //easier way to create media queries, no useMediaQuery hook needed.
    sx: {
    fontSize: {
    xs: '10px',
    sm: '11px',
    md: '12px',
    lg: '13px',
    xl: '14px',
    },
    },
    }}
    />

    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 Material UI Docs.

    Material UI Theme

    Material React Table respects your Material UI Theme. If you have already set up Material UI and a global Material UI Theme, you should already be set. But if you have not, you should visit the offical Material UI Theming Docs to learn how to set that up.

    function App() {
    //Have you setup your Mui Theme globally in your app root?
    return (
    <ThemeProvider theme={createTheme({...})}>
    ...rest of your application
    </ThemeProvider>
    );
    }

    Customize Theme Just for your Table

    Thanks to Material UI allowing you to nest multiple Theme Providers, you can change your Material UI Theme just for the <MaterialReactTable /> component by wrapping a <ThemeProvider theme={createTheme(...)}> around just your table. The values in this theme will only effect the <MaterialReactTable /> 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.

    import { createTheme, ThemeProvider } from '@mui/material';
    //in one of your normal components
    return (
    <ThemeProvider theme={createTheme({...})}>
    <MaterialReactTable columns={columns} data={data} />
    </ThemeProvider>
    );

    Important Theme Values used by Material React Table

    <MaterialReactTable /> will primarily use the following values internally from your Material UI Theme by default:

    • theme.palette.background.default - used as the background color for most table components by default

    • theme.palette.divider - used in dividers in menus and for the column resizing handle

    • theme.palette.info.main - used in the Toolbar Alert Banner and the Toolbar DropZone component

    • theme.palette.primary.main - used as the primary color for anything colorful in the table (input fields, checkboxes, dragging borders, etc.)

    Notice that by default, the secondary color isn't used at all. Remember though that you can always override which color a component uses by passing in a mui...Props prop, like how we changed checkboxes to use the secondary color in the example above.

    Custom Material UI 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.


    Demo

    Open StackblitzOpen Code SandboxOpen on GitHub
    DylanMurray261 Erdman FordEast DaphneKentucky
    RaquelKohler769 Dominic GroveColumbusOhio
    ErvinReinger566 Brakus InletSouth LindaWest Virginia
    BrittanyMcCullough722 Emie StreamLincolnNebraska
    BransonFrami32188 Larkin TurnpikeCharlestonSouth Carolina

    Rows per page

    1-5 of 5

    Source Code

    1import React, { useMemo } from 'react';
    2import { MaterialReactTable, type MRT_ColumnDef } from 'material-react-table';
    3import { createTheme, ThemeProvider, useTheme } from '@mui/material';
    4
    5type Person = {
    6 firstName: string;
    7 lastName: string;
    8 address: string;
    9 city: string;
    10 state: string;
    11};
    12
    13//column definitions...
    37
    38//data definitions...
    77
    78const Example = () => {
    79 const globalTheme = useTheme(); //(optional) if you already have a theme defined in your app root, you can import here
    80
    81 const tableTheme = useMemo(
    82 () =>
    83 createTheme({
    84 palette: {
    85 mode: globalTheme.palette.mode, //let's use the same dark/light mode as the global theme
    86 primary: globalTheme.palette.secondary, //swap in the secondary color as the primary for the table
    87 info: {
    88 main: 'rgb(255,122,0)', //add in a custom color for the toolbar alert background stuff
    89 },
    90 background: {
    91 default:
    92 globalTheme.palette.mode === 'light'
    93 ? 'rgb(254,255,244)' //random light yellow color for the background in light mode
    94 : '#000', //pure black table in dark mode for fun
    95 },
    96 },
    97 typography: {
    98 button: {
    99 textTransform: 'none', //customize typography styles for all buttons in table by default
    100 fontSize: '1.2rem',
    101 },
    102 },
    103 components: {
    104 MuiTooltip: {
    105 styleOverrides: {
    106 tooltip: {
    107 fontSize: '1.1rem', //override to make tooltip font size larger
    108 },
    109 },
    110 },
    111 MuiSwitch: {
    112 styleOverrides: {
    113 thumb: {
    114 color: 'pink', //change the color of the switch thumb in the columns show/hide menu to pink
    115 },
    116 },
    117 },
    118 },
    119 }),
    120 [globalTheme],
    121 );
    122
    123 return (
    124 <ThemeProvider theme={tableTheme}>
    125 <MaterialReactTable
    126 columns={columns}
    127 data={data}
    128 enableRowSelection
    129 enableColumnOrdering
    130 enablePinning
    131 />
    132 </ThemeProvider>
    133 );
    134};
    135
    136export default Example;
    137

    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 muiTablePaperProps 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.

    <MaterialReactTable
    columns={columns}
    data={data}
    muiTablePaperProps={{
    elevation: 0, //change the mui box shadow
    //customize paper styles
    sx: {
    borderRadius: '0',
    border: '1px dashed #e0e0e0',
    },
    }}
    />

    Customize Table Body, Rows, Columns, and Cells

    Stripe Rows Example

    If you need to style many of the rows or columns in a consistent manner, it usually makes sense to style the <TableBody /> component itself. For example if you want to stripe the rows, you can do something like this:

    <MaterialReactTable
    columns={columns}
    data={data}
    muiTableBodyProps={{
    sx: {
    //stripe the rows, make odd rows a darker color
    '& tr:nth-of-type(odd)': {
    backgroundColor: '#f5f5f5',
    },
    },
    }}
    />

    Stripe Columns Example

    Similarly, if you want to stripe the columns, you can do something like this:

    <MaterialReactTable
    columns={columns}
    data={data}
    muiTableBodyProps={{
    sx: {
    //stripe the rows, make odd rows a darker color
    '& td:nth-of-type(odd)': {
    backgroundColor: '#f5f5f5',
    },
    },
    }}
    muiTableBodyCellProps={{
    sx: {
    borderRight: '2px solid #e0e0e0', //add a border between columns
    },
    }}
    />

    Demo

    1DylanSprouseMurray261 Erdman FordEast DaphneKentucky
    2RaquelHakeemKohler769 Dominic GroveColumbusOhio
    3ErvinKrisReinger566 Brakus InletSouth LindaWest Virginia
    4BrittanyKathrynMcCullough722 Emie StreamLincolnNebraska
    5BransonJohnFrami32188 Larkin TurnpikeCharlestonSouth Carolina

    Rows per page

    1-5 of 5

    Source Code

    1import React, { useMemo } from 'react';
    2import { MaterialReactTable, type MRT_ColumnDef } from 'material-react-table';
    3import { data, type Person } from './makeData';
    4import { darken } from '@mui/material';
    5
    6const Example = () => {
    7 const columns = useMemo<MRT_ColumnDef<Person>[]>(
    8 //column definitions...
    44 );
    45
    46 return (
    47 <MaterialReactTable
    48 columns={columns}
    49 data={data}
    50 muiTablePaperProps={{
    51 elevation: 0,
    52 sx: {
    53 borderRadius: '0',
    54 border: '1px dashed #e0e0e0',
    55 },
    56 }}
    57 muiTableBodyProps={{
    58 sx: (theme) => ({
    59 '& tr:nth-of-type(odd)': {
    60 backgroundColor: darken(theme.palette.background.default, 0.1),
    61 },
    62 }),
    63 }}
    64 />
    65 );
    66};
    67
    68export default Example;
    69