MRT logoMantine React Table

On This Page

    Toolbar Customization Guide

    This guide shows you how to hide, customize, or override the top and bottom toolbars in Mantine React Table.

    Note: This guide has become much more simple since the introduction of the useMantineReactTable hook.
    No more tableInstanceRef hacks required!

    Relevant Table Options

    #
    Prop Name
    Type
    Default Value
    More Info Links
    1booleantrueMRT Customize Toolbars Docs
    2booleantrue
    3booleantrue
    4BoxProps | ({ table }) => BoxPropsMantine Toolbar Docs
    5ProgressProps | ({ isTopToolbar, table }) => ProgressPropsMantine Progress Docs
    6BadgeProps| ({ table }} => BadgePropsMantine Chip Docs
    7AlertProps | ({ table }) => AlertPropsMantine Alert Docs
    8BoxProps | ({ table }) => BoxPropsMantine Toolbar Docs
    9'left' | 'right'
    10'bottom' | 'top' | 'both'
    11'bottom' | 'top' | 'head-overlay' | 'none'
    12'bottom' | 'top' | 'both' | 'none'
    13ReactNode | ({ table }) => ReactNode
    14({ table }) => ReactNode
    15({ table }) => ReactNode
    16ReactNode | ({ table }) => ReactNode
    17({ table }) => ReactNode

    Relevant State

    #
    State Option
    Type
    Default Value
    More Info Links
    1booleanfalse
    2booleanfalse

    Hide or Disable Toolbars

    There are enableTopToolbar and enableBottomToolbar table options that you can use to show or hide the toolbars.

    const table = useMantineReactTable({
      data,
      columns,
      enableTopToolbar: false,
      enableBottomToolbar: false,
    });
    
    return <MantineReactTable table={table} />;

    Alternatively, you could just use a different MRT component that does not have the toolbars built-in. For example, use the <MRT_TableContainer /> or <MRT_Table /> components instead of the <MantineReactTable /> component.

    const table = useMantineReactTable({
      data,
      columns,
    });
    
    //This MRT sub-component does not contain the code for the toolbars. MRT_TablePaper and MantineReactTable do.
    return <MRT_TableContainer table={table} />;

    No Toolbars Example

    First Name
    Last Name
    Address
    City
    State
    WavaHoppe4456 Towne EstatesEdmondNew Jersey
    KamrenKemmer237 Reinger ViewKesslermouthNew Jersey
    DillonHackett79266 Cronin RestConroylandColorado
    WilberVon4162 Della RoadsChampaignIdaho
    RonnyLowe4057 Burley ExtensionsSiennasteadAlaska
    LaviniaKreiger24310 Aufderhar UnionCeceliachesterKentucky
    TracyWilkinson7204 Claudine SummitFort MelanychesterTennessee
    import '@mantine/core/styles.css';
    import '@mantine/dates/styles.css'; //if using mantine date picker features
    import 'mantine-react-table/styles.css'; //make sure MRT styles were imported in your app root (once)
    import classes from './CSS.module.css';
    import clsx from 'clsx';
    import { useMemo } from 'react';
    import {
      type MRT_ColumnDef,
      MRT_Table,
      useMantineReactTable,
    } from 'mantine-react-table';
    import { useMantineColorScheme } from '@mantine/core';
    import { data, type Person } from './makeData';
    
    export const Example = () => {
      const { colorScheme } = useMantineColorScheme();
    
      const columns = useMemo<MRT_ColumnDef<Person>[]>(
        () => [
          {
            accessorKey: 'firstName',
            header: 'First Name',
          },
          {
            accessorKey: 'lastName',
            header: 'Last Name',
          },
          {
            accessorKey: 'address',
            header: 'Address',
          },
          {
            accessorKey: 'city',
            header: 'City',
          },
          {
            accessorKey: 'state',
            header: 'State',
          },
        ],
        [],
      );
    
      const table = useMantineReactTable({
        columns,
        data,
        enableColumnActions: false,
        enableColumnFilters: false,
        enablePagination: false,
        enableSorting: false,
        mantineTableProps: {
          className: clsx(classes.table),
          highlightOnHover: false,
          striped: 'odd',
          withColumnBorders: true,
          withRowBorders: true,
          withTableBorder: true,
        },
      });
    
      //using MRT_Table instead of MantineReactTable if we do not want any of the toolbar features
      return <MRT_Table table={table} />;
    };
    
    export default Example;

    Customize Toolbar buttons

    Everything in the toolbars are customizable. You can add your own buttons or change the order of the built-in buttons.

    Customize Built-In Internal Toolbar Button Area

    The renderToolbarInternalActions table option allows you to redefine the built-in buttons that usually reside in the top right of the top toolbar. You can reorder the icon buttons or even insert your own custom buttons. All of the built-in buttons are available to be imported from 'mantine-react-table'.

    import {
      MantineReactTable,
      MRT_ShowHideColumnsButton,
      MRT_ToggleFullScreenButton,
    } from 'mantine-react-table';
    
    const table = useMantineReactTable({
      data,
      columns,
      renderToolbarInternalActions: ({ table }) => (
        <>
          {/* add your own custom print button or something */}
          <IconButton onClick={() => showPrintPreview(true)}>
            <PrintIcon />
          </IconButton>
          {/* built-in buttons (must pass in table prop for them to work!) */}
          <MRT_ShowHideColumnsButton table={table} />
          <MRT_ToggleFullScreenButton table={table} />
        </>
      ),
    });
    
    return <MantineReactTable table={table} />;

    Add Custom Toolbar Buttons/Components

    The renderTopToolbarCustomActions and renderBottomToolbarCustomActions table options allow you to add your own custom buttons or components to the top and bottom toolbar areas. These props are functions that return a ReactNode. You can add your own buttons or whatever components you want.

    In all of these render... table options, you get access to the table instance that you can use to perform actions or extract data from the table.

    const table = useMantineReactTable({
      data,
      columns,
      enableRowSelection: true,
      //Simply adding a table title to the top-left of the top toolbar
      renderTopToolbarCustomActions: () => (
        <Typography variant="h3">Customer's Table</Typography>
      ),
      //Adding a custom button to the bottom toolbar
      renderBottomToolbarCustomActions: ({ table }) => (
        <Button
          variant="contained"
          color="lightblue"
          //extract all selected rows from the table instance and do something with them
          onClick={() => handleDownloadRows(table.getSelectedRowModel().rows)}
        >
          Download Selected Rows
        </Button>
      ),
    });
    
    return <MantineReactTable table={table} />;

    Custom Toolbar Actions Example

    First Name
    Last Name
    Age
    Salary
    HomerSimpson3953000
    MargeSimpson3860000
    BartSimpson1046000
    LisaSimpson8120883
    MaggieSimpson122

    Rows per page

    1-5 of 5

    import '@mantine/core/styles.css';
    import '@mantine/dates/styles.css'; //if using mantine date picker features
    import 'mantine-react-table/styles.css'; //make sure MRT styles were imported in your app root (once)
    import { useMemo } from 'react';
    import {
      MRT_ToggleDensePaddingButton,
      MRT_ToggleFullScreenButton,
      MantineReactTable,
      type MRT_ColumnDef,
      useMantineReactTable,
    } from 'mantine-react-table';
    import { Box, Button, ActionIcon, Flex } from '@mantine/core';
    import { IconPrinter } from '@tabler/icons-react';
    import { data, type Person } from './makeData';
    
    const Example = () => {
      const columns = useMemo<MRT_ColumnDef<Person>[]>(
        () => [
          {
            accessorKey: 'firstName',
            header: 'First Name',
          },
          {
            accessorKey: 'lastName',
            header: 'Last Name',
          },
          {
            accessorKey: 'age',
            header: 'Age',
          },
          {
            accessorKey: 'salary',
            header: 'Salary',
          },
        ],
        [],
      );
    
      const table = useMantineReactTable({
        columns,
        data,
        enableRowSelection: true,
        positionToolbarAlertBanner: 'bottom',
        //add custom action buttons to top-left of top toolbar
        renderTopToolbarCustomActions: ({ table }) => (
          <Box style={{ display: 'flex', gap: '16px', padding: '4px' }}>
            <Button
              color="teal"
              onClick={() => {
                alert('Create New Account');
              }}
              variant="filled"
            >
              Create Account
            </Button>
            <Button
              color="red"
              disabled={!table.getIsSomeRowsSelected()}
              onClick={() => {
                alert('Delete Selected Accounts');
              }}
              variant="filled"
            >
              Delete Selected Accounts
            </Button>
          </Box>
        ),
        //customize built-in buttons in the top-right of top toolbar
        renderToolbarInternalActions: ({ table }) => (
          <Flex gap="xs" align="center">
            {/* add custom button to print table  */}
            <ActionIcon
              onClick={() => {
                window.print();
              }}
            >
              <IconPrinter />
            </ActionIcon>
            {/* along-side built-in buttons in whatever order you want them */}
            <MRT_ToggleDensePaddingButton table={table} />
            <MRT_ToggleFullScreenButton table={table} />
          </Flex>
        ),
      });
    
      return <MantineReactTable table={table} />;
    };
    
    export default Example;

    Position Toolbar Areas

    The positionToolbarAlertBanner, positionGlobalFilter, positionPagination, and positionToolbarDropZone table options allow you to swap the default position of certain areas of the toolbars. Experiment moving them around until you find a layout that works for you.

    const table = useMantineReactTable({
      data,
      columns
      //if rendering top toolbar buttons, sometimes you want alerts to be at the bottom
      positionToolbarAlertBanner: 'bottom',
      positionGlobalFilter: 'left', //move the search box to the left of the top toolbar
      positionPagination: 'top',
      renderTopToolbarCustomActions: () => <Box>...</Box>,
    });
    
    return <MantineReactTable table={table} />;

    Customize Toolbar Props and Styles

    The mantineTopToolbarProps, mantineBottomToolbarProps, mantineToolbarAlertBannerProps, and mantineToolbarAlertBannerBadgeProps table options allow you to customize the props and styles of the underlying Mantine components that make up the toolbar components. Remember that you can pass CSS overrides to their sx or style props. Some have found this useful for forcing position: absolute on alerts, etc.

    Customize Linear Progress Bars

    The progress bars that display in both the top and bottom toolbars become visible when either the isLoading or showProgressBars state options are set to true. You can customize the progress bars by passing in props to the mantineProgressProps table option. By default, the progress bars have a full animated progress bar, but you can set the value prop to a number between 0 and 100 to show real progress values if your table is doing some complicated long running tasks that you want to show progress for. Visit the Mantine Progress docs to learn more.

    const table = useMantineReactTable({
      data,
      columns,
      mantineProgressProps: ({ isTopToolbar }) => ({
        color: 'orange',
        style: { display: isTopToolbar ? 'block' : 'none' }, //only show top toolbar progress bar
        value: fetchProgress, //show precise real progress value if you so desire
      }),
      state: {
        isLoading,
        showProgressBars,
      },
    });
    
    return <MantineReactTable table={table} />;

    Customize Toolbar Alert Banner

    The toolbar alert banner is an internal component used to display alerts to the user. By default, it will automatically show messages around the number of selected rows or grouping state.

    However, you can repurpose this alert banner to show your own custom messages too. You can force the alert banner to show by setting the showAlertBanner state option to true. You can then customize the messages and other stylings using the mantineToolbarAlertBannerProps to create your custom message. You probably saw this in the Remote Data or React Query examples.

    const table = useMantineReactTable({
      data,
      columns,
      //show a custom error message if there was an error fetching data in the top toolbar
      mantineToolbarAlertBannerProps: isError
        ? {
            color: 'red',
            children: 'Network Error. Could not fetch data.',
          }
        : undefined,
      state: {
        showAlertBanner: isError,
        showProgressBars: isFetching,
      },
    });
    
    return <MantineReactTable table={table} />;

    Override with Custom Toolbar Components

    If you want to completely override the default toolbar components, you can do so by passing in your own custom components to the renderTopToolbar and renderBottomToolbar props.

    The drawback to this approach is that you will not get all the automatic features of the default toolbar components, such as the automatic alert banner, progress bars, etc. You will have to implement all of that yourself if you still want those features. Though you can also just import those MRT components and use them in your custom toolbar.

    import {
      MRT_GlobalFilterTextInput,
      MRT_TablePagination,
      MantineReactTable,
      useMantineReactTable,
    } from 'mantine-react-table';
    
    const table = useMantineReactTable({
      data,
      columns,
      renderTopToolbar: ({ table }) => (
        <Flex align="center" justify="space-between">
          <MRT_GlobalFilterTextInput table={table} />
          <MRT_TablePagination table={table} />
        </Flex>
      ),
      renderBottomToolbar: ({ table }) => (
        <Box>
          <Button>Download</Button>
        </Box>
      ),
    });
    
    return <MantineReactTable table={table} />;

    Build Your Own Toolbar

    Instead of overriding the toolbar components up above, you may want 100% control over the layout and styling of your table controls and where they are on the page. You can do this by just using a MRT sub component such as <MRT_TableContainer /> for the table component, which does not have the internal toolbar components built-in. Optionally, build your own custom toolbar components using the other MRT sub components.

    Hey I'm some page content. I'm just one of your normal components between your custom toolbar and the MRT Table below

    First Name
    Last Name
    Age
    Salary
    HomerSimpson3953000
    MargeSimpson386000
    BartSimpson10460
    LisaSimpson8120883
    MaggieSimpson122
    NedFlanders60100000
    ApuNahasapeemapetilon4080000
    MontgomeryBurns10010000000
    WaylonSmithers4580000
    EdnaKrabappel5580000

    Rows per page

    1-10 of 11

    import '@mantine/core/styles.css';
    import '@mantine/dates/styles.css'; //if using mantine date picker features
    import 'mantine-react-table/styles.css'; //make sure MRT styles were imported in your app root (once)
    import {
      MRT_GlobalFilterTextInput,
      MRT_ShowHideColumnsButton,
      MRT_TablePagination,
      MRT_ToggleDensePaddingButton,
      MRT_ToggleFiltersButton,
      MRT_ToolbarAlertBanner,
      useMantineReactTable,
      type MRT_ColumnDef,
      MRT_TableContainer,
    } from 'mantine-react-table';
    import {
      ActionIcon,
      Box,
      Button,
      Flex,
      Text,
      Tooltip,
      rgba,
    } from '@mantine/core';
    import { IconPrinter } from '@tabler/icons-react';
    import { data, type Person } from './makeData';
    
    const columns: MRT_ColumnDef<Person>[] = [
      {
        accessorKey: 'firstName',
        header: 'First Name',
      },
      {
        accessorKey: 'lastName',
        header: 'Last Name',
      },
      {
        accessorKey: 'age',
        header: 'Age',
      },
      {
        accessorKey: 'salary',
        header: 'Salary',
      },
    ];
    
    const Example = () => {
      const table = useMantineReactTable({
        columns,
        data,
        enableRowSelection: true,
        initialState: { showGlobalFilter: true },
      });
    
      return (
        <Box style={{ border: 'gray 2px dashed', padding: '16px' }}>
          {/* Our Custom External Top Toolbar */}
          <Flex
            style={(theme) => ({
              backgroundColor: rgba(theme.colors.blue[3], 0.2),
              borderRadius: '4px',
              flexDirection: 'row',
              gap: '16px',
              justifyContent: 'space-between',
              padding: '24px 16px',
              '@media max-width: 768px': {
                flexDirection: 'column',
              },
            })}
          >
            <Box>
              <Button
                color="lightblue"
                onClick={() => {
                  alert('Add User');
                }}
                variant="filled"
              >
                Crete New Account
              </Button>
            </Box>
            <MRT_GlobalFilterTextInput table={table} />
            <Flex gap="xs" align="center">
              <MRT_ToggleFiltersButton table={table} />
              <MRT_ShowHideColumnsButton table={table} />
              <MRT_ToggleDensePaddingButton table={table} />
              <Tooltip label="Print">
                <ActionIcon onClick={() => window.print()}>
                  <IconPrinter />
                </ActionIcon>
              </Tooltip>
            </Flex>
          </Flex>
          {/* Some Page Content */}
          <Text p="16px 4px">
            {
              "Hey I'm some page content. I'm just one of your normal components between your custom toolbar and the MRT Table below"
            }
          </Text>
          {/* The MRT Table with no toolbars built-in */}
          <MRT_TableContainer table={table} />
          {/* Our Custom Bottom Toolbar */}
          <Box>
            <Flex justify="flex-end">
              <MRT_TablePagination table={table} />
            </Flex>
            <Box style={{ display: 'grid', width: '100%' }}>
              <MRT_ToolbarAlertBanner stackAlertBanner table={table} />
            </Box>
          </Box>
        </Box>
      );
    };
    
    export default Example;