MRT logoMantine React Table

On This Page

    Detail Panel (Expanding) Feature Guide

    Mantine React Table has multiple kinds of expanding features. This guide will show you how to use the detail panel feature to expand a single row to show more information for that row.

    If you are looking for how to expand multiple rows from a tree data structure, see the Expanding Sub-Rows guide.

    Relevant Table Options

    #
    Prop Name
    Type
    Default Value
    More Info Links
    1{ [key: string]: MRT_ColumnDef<TData> }MRT Display Columns Docs
    2'first' | 'last'
    3({ row, table }) => ReactNode

    Relevant State

    #
    State Option
    Type
    Default Value
    More Info Links
    1Record<string, boolean> | boolean{}TanStack Table Expanding Docs

    Render Detail Panel

    To add a detail panel to a row, all you need to do is add a renderDetailPanel table option.

    The recommended way to access the row data for the detail panel is to pull from the original object on a row. This gives you the original data for the row, not transformed or filtered by TanStack Table.

    Using row.getValue('columnId') will not work for data that does not have its own column. Using row.original.columnId is recommended for detail panels since the data in the detail panel usually does not have its own column.

    ID
    First Name
    Middle Name
    Last Name
    1DylanSprouseMurray
    2RaquelHakeemKohler
    3ErvinKrisReinger
    4BrittanyKathrynMcCullough
    5BransonJohnFrami

    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 { MantineReactTable, type MRT_ColumnDef } from 'mantine-react-table';
    import { Box, Text } from '@mantine/core';
    import { data, type Person } from './makeData';
    
    const Example = () => {
      const columns = useMemo(
        () =>
          [
            {
              accessorKey: 'id',
              header: 'ID',
              size: 50,
            },
            {
              accessorKey: 'firstName',
              header: 'First Name',
            },
            {
              accessorKey: 'middleName',
              header: 'Middle Name',
            },
            {
              accessorKey: 'lastName',
              header: 'Last Name',
            },
          ] as MRT_ColumnDef<Person>[],
        [],
      );
    
      return (
        <MantineReactTable
          columns={columns}
          data={data}
          renderDetailPanel={({ row }) => (
            <Box
              style={{
                display: 'grid',
                margin: 'auto',
                gridTemplateColumns: '1fr 1fr',
                width: '100%',
              }}
            >
              <Text>Address: {row.original.address}</Text>
              <Text>City: {row.original.city}</Text>
              <Text>State: {row.original.state}</Text>
              <Text>Country: {row.original.country}</Text>
            </Box>
          )}
        />
      );
    };
    
    export default Example;

    Expand Detail Panel By Default

    If you want some or all rows to be expanded by default, you can specify that in the initialState.expanded table option. Pass true to expand all rows, or specify which rowIds should be expanded.

    //expand first 2 rows by default
    const table = useMantineReactTable({
      data,
      columns,
      initialState: {
        expanded: {
          1: true,
          2: true,
        },
      },
    });
    //expand all rows by default
    const table = useMantineReactTable({
      data,
      columns,
      initialState: {
        expanded: true,
      },
    });

    Position Expand Column Last

    If you want to position the expand column last, you can set the positionExpandColumn table option to 'last'.

    ID
    First Name
    Middle Name
    Last Name
    1DylanSprouseMurray

    Address: 261 Erdman Ford

    City: East Daphne

    State: Kentucky

    Country: United States

    2RaquelHakeemKohler

    Address: 769 Dominic Grove

    City: Vancouver

    State: British Columbia

    Country: Canada

    3ErvinKrisReinger

    Address: 566 Brakus Inlet

    City: South Linda

    State: West Virginia

    Country: United States

    Rows per page

    1-3 of 3

    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 { MantineReactTable, type MRT_ColumnDef } from 'mantine-react-table';
    import { Box, Text } from '@mantine/core';
    import { data, type Person } from './makeData';
    
    const Example = () => {
      const columns = useMemo<MRT_ColumnDef<Person>[]>(
        () => [
          {
            accessorKey: 'id',
            header: 'ID',
            size: 50,
          },
          {
            accessorKey: 'firstName',
            header: 'First Name',
          },
          {
            accessorKey: 'middleName',
            header: 'Middle Name',
          },
          {
            accessorKey: 'lastName',
            header: 'Last Name',
          },
        ],
        [],
      );
    
      return (
        <MantineReactTable
          columns={columns}
          data={data}
          displayColumnDefOptions={{
            'mrt-row-expand': {
              mantineTableHeadCellProps: {
                align: 'right',
              },
              mantineTableBodyCellProps: {
                align: 'right',
              },
            },
          }}
          initialState={{ expanded: true }}
          renderDetailPanel={({ row }) => (
            <Box
              style={{
                display: 'grid',
                margin: 'auto',
                gridTemplateColumns: '1fr 1fr',
                width: '100%',
              }}
            >
              <Text>Address: {row.original.address}</Text>
              <Text>City: {row.original.city}</Text>
              <Text>State: {row.original.state}</Text>
              <Text>Country: {row.original.country}</Text>
            </Box>
          )}
          positionExpandColumn="last"
        />
      );
    };
    
    export default Example;

    View Extra Storybook Examples