MRT logoMaterial React Table

Legacy V2 Docs
On This Page

    Display (Built-in) Columns Guide

    Display columns are used to display non-data elements in a table. They only require an id and header in the column definition. They do not need an accessorKey or accessorFn, as they are not meant to connect to your data at all.

    Display columns do not have any processing features, such as sorting, filtering, grouping, etc. enabled on them by default.

    Relevant Table Options

    1
    Partial<MRT_DisplayColumnDef<TData>>
    MRT Display Columns Docs
    2
    { [key: string]: MRT_DisplayColumnDef<TData> }
    MRT Display Columns Docs

    Built-in MRT Display Columns

    Material React Table has a few built-in display columns that are created automatically when certain features are enabled.

    • mrt-row-pin - created when enableRowPinning table option is true with certain rowPinningDisplayMode values

    • mrt-row-drag - created when enableRowDragging or enableRowOrdering table option are true

    • mrt-row-actions - created when enableRowActions (or sometimes when enableEditing) props are true

    • mrt-row-expand - created when enableExpanding, enableGrouping, or renderDetailPanel props are true

    • mrt-row-select - created when enableRowSelection table option is true

    • mrt-row-numbers - created when enableRowNumbers table option is true

    • mrt-row-spacer - created when layoutMode is "grid-no-grow" (column resizing)

    Display columns are, for the most part, the same as a data column, except they do not have an accessor to access data. When a display column is created internally by Material React Table, the following options are all set to false by default:

    const defaultDisplayColumnDefOptions = {
    columnDefType: 'display',
    enableClickToCopy: false,
    enableColumnActions: false,
    enableColumnDragging: false,
    enableColumnFilter: false,
    enableColumnOrdering: false,
    enableEditing: false,
    enableGlobalFilter: false,
    enableGrouping: false,
    enableHiding: false,
    enableResizing: false,
    enableSorting: false,
    } as Partial<MRT_ColumnDef>;

    All of these values are able to be overridden if needed, and you'll learn about that in the next section down below.

    Customize Built-in MRT Display Columns

    It is possible to change and override the default behavior of built-in display columns. Whether you want to change the default column width, add some styles, or enable some features, such as column actions or column drag and drop, you can do it with the displayColumnDefOptions table option.

    Default Display Column Table Option

    First of all, if you want to enable or disable some feature for all display columns, you can just use the defaultDisplayColumn table option. This will apply to all display columns, including any custom display columns you create.

    const table = useMaterialReactTable({
    columns,
    data,
    defaultDisplayColumn: {
    enableColumnOrdering: true,
    enableColumnResizing: true,
    minSize: 100,
    },
    });

    Display Column Definition Options Table Option

    Let's say you need to adjust the width of the Actions column to be wide enough to fit all of your action buttons. You could do that as follows:

    const table = useMaterialReactTable({
    columns,
    data,
    displayColumnDefOptions: { 'mrt-row-actions': { size: 300 } }, //change width of actions column to 300px
    enableRowActions: true,
    renderRowActions: ({ row }) => (
    <Box>
    <Button>Action 1</Button>
    <Button>Action 2</Button>
    <Button>Action 3</Button>
    </Box>
    ),
    });
    return <MaterialReactTable table={table} />;

    Or maybe you want to enable a feature that is off by default for display columns, such as column ordering or pinning.

    const table = useMaterialReactTable({
    columns,
    data,
    displayColumnDefOptions: {
    'mrt-row-numbers': {
    enableOrdering: true,
    enablePinning: true,
    enableColumnActions: true,
    size: 40,
    grow: true, //new in v2.8
    },
    },
    enableRowNumbers: true,
    });
    return <MaterialReactTable table={table} />;

    Here is a full example and demo for customizing display columns.

    Demo

    Open StackblitzOpen Code SandboxOpen on GitHub








    1DylanMurray261 Erdman FordEast DaphneKentucky
    2RaquelKohler769 Dominic GroveColumbusOhio
    3ErvinReinger566 Brakus InletSouth LindaWest Virginia
    4BrittanyMcCullough722 Emie StreamLincolnNebraska
    5BransonFrami32188 Larkin TurnpikeCharlestonSouth Carolina
    1-5 of 5

    Source Code

    1import { useMemo } from 'react';
    2import { Box, Button } from '@mui/material';
    3import {
    4 MaterialReactTable,
    5 useMaterialReactTable,
    6 type MRT_ColumnDef,
    7} from 'material-react-table';
    8import { data, type Person } from './makeData';
    9
    10const Example = () => {
    11 const columns = useMemo<MRT_ColumnDef<Person>[]>(
    12 //column definitions...
    37 );
    38
    39 const table = useMaterialReactTable({
    40 columns,
    41 data,
    42 defaultDisplayColumn: {
    43 enableResizing: true, //turn on some features that are usually off for all display columns
    44 },
    45 displayColumnDefOptions: {
    46 'mrt-row-actions': {
    47 size: 350, //set custom width
    48 muiTableHeadCellProps: {
    49 align: 'center', //change head cell props
    50 },
    51 },
    52 'mrt-row-numbers': {
    53 enableColumnDragging: true,
    54 enableColumnOrdering: true, //turn on some features that are usually off
    55 enableResizing: true,
    56 muiTableHeadCellProps: {
    57 sx: {
    58 fontSize: '1.2rem',
    59 },
    60 },
    61 },
    62 'mrt-row-select': {
    63 enableColumnActions: true,
    64 enableHiding: true,
    65 size: 100,
    66 },
    67 },
    68 enableColumnResizing: true,
    69 enableColumnOrdering: true,
    70 enableRowNumbers: true,
    71 enableRowSelection: true,
    72 enableRowActions: true,
    73 renderRowActions: ({ row }) => (
    74 <Box sx={{ display: 'flex', gap: '1rem' }}>
    75 <Button>Button 1</Button>
    76 <Button>Button 2</Button>
    77 <Button>Button 3</Button>
    78 </Box>
    79 ),
    80 });
    81
    82 return <MaterialReactTable table={table} />;
    83};
    84
    85export default Example;
    86

    Create your own Display Columns

    You do not have to use the built in Row Actions feature. You can just create your own display columns instead. It is as easy as creating a normal column, only specifying the columnDefType as display.

    const columns = [
    {
    id: 'sendEmail',
    header: 'Send Email',
    columnDefType: 'display', //turns off data column features like sorting, filtering, etc.
    enableColumnOrdering: true, //but you can turn back any of those features on if you want like this
    Cell: ({ row }) => (
    <Button onClick={() => sendEmail(row.original.userId)}>Send Email</Button>
    ),
    },
    {
    id: 'name',
    header: 'Name',
    accessorKey: 'name',
    },
    ];