MRT logoMaterial React Table

On This Page

    Row Actions Feature Guide

    The row actions feature is simply a pre-built Display Column feature that adds a column as a place to store either a row action menu or other row action buttons.

    Using the built-in Row Actions column is optional, as you can simply create your own display columns, but this feature has some built-in conveniences that make it easy to add row actions to your table.

    Relevant Table Options

    1
    { [key: string]: MRT_DisplayColumnDef<TData> }
    MRT Display Columns Docs
    2
    boolean
    3
    'first' | 'last'
    4
    ({ closeMenu, row, table }) => ReactNode[]
    5
    ({ cell, row, table }) => ReactNode

    Enable Row Actions

    You can enable the row actions feature by setting the enableRowActions prop to true.

    You can then add your row action components with either the renderRowActions or renderRowActionMenuItems props.

    Add Row Actions Menu Items

    If you want to embed all of your row actions into a single menu, you can use the renderRowActionMenuItems prop.

    <MaterialReactTable
    enableRowActions
    renderRowActionMenuItems={({ row }) => [
    <MenuItem key="edit" onClick={() => console.info('Edit')}>
    Edit
    </MenuItem>,
    <MenuItem key="delete" onClick={() => console.info('Delete')}>
    Delete
    </MenuItem>,
    ]}
    />

    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

    1-5 of 5

    Source Code

    1import { useMemo } from 'react';
    2import { MaterialReactTable, type MRT_ColumnDef } from 'material-react-table';
    3import { data, type Person } from './makeData';
    4import { MenuItem } from '@mui/material';
    5
    6export const Example = () => {
    7 const columns = useMemo<MRT_ColumnDef<Person>[]>(
    8 //column definitions...
    33 );
    34
    35 return (
    36 <MaterialReactTable
    37 columns={columns}
    38 data={data}
    39 enableRowActions
    40 renderRowActionMenuItems={({ row }) => [
    41 <MenuItem key="edit" onClick={() => console.info('Edit')}>
    42 Edit
    43 </MenuItem>,
    44 <MenuItem key="delete" onClick={() => console.info('Delete')}>
    45 Delete
    46 </MenuItem>,
    47 ]}
    48 />
    49 );
    50};
    51
    52export default Example;
    53

    Add Row Action Buttons

    If you want to add row action buttons, you can use the renderRowActions prop.

    <MaterialReactTable
    enableRowActions
    renderRowActions={({ row }) => (
    <Box>
    <IconButton onClick={() => console.info('Edit')}>
    <EditIcon />
    </IconButton>
    <IconButton onClick={() => console.info('Delete')}>
    <DeleteIcon />
    </IconButton>
    </Box>
    )}
    />

    Demo

    DylanMurray261 Erdman FordEast DaphneKentucky
    RaquelKohler769 Dominic GroveColumbusOhio
    ErvinReinger566 Brakus InletSouth LindaWest Virginia
    BrittanyMcCullough722 Emie StreamLincolnNebraska
    BransonFrami32188 Larkin TurnpikeCharlestonSouth Carolina

    1-5 of 5

    Source Code

    1import { useMemo, useState } from 'react';
    2import { MaterialReactTable, type MRT_ColumnDef } from 'material-react-table';
    3import { Box, IconButton } from '@mui/material';
    4import {
    5 Edit as EditIcon,
    6 Delete as DeleteIcon,
    7 Email as EmailIcon,
    8} from '@mui/icons-material';
    9import { data as initialData, type Person } from './makeData';
    10
    11export const Example = () => {
    12 const columns = useMemo<MRT_ColumnDef<Person>[]>(
    13 //column definitions...
    38 );
    39
    40 const [data, setData] = useState<Person[]>(initialData);
    41
    42 return (
    43 <MaterialReactTable
    44 columns={columns}
    45 data={data}
    46 enableRowActions
    47 renderRowActions={({ row, table }) => (
    48 <Box sx={{ display: 'flex', flexWrap: 'nowrap', gap: '8px' }}>
    49 <IconButton
    50 color="primary"
    51 onClick={() =>
    52 window.open(
    53 `mailto:kevinvandy@mailinator.com?subject=Hello ${row.original.firstName}!`,
    54 )
    55 }
    56 >
    57 <EmailIcon />
    58 </IconButton>
    59 <IconButton
    60 color="secondary"
    61 onClick={() => {
    62 table.setEditingRow(row);
    63 }}
    64 >
    65 <EditIcon />
    66 </IconButton>
    67 <IconButton
    68 color="error"
    69 onClick={() => {
    70 data.splice(row.index, 1); //assuming simple data table
    71 setData([...data]);
    72 }}
    73 >
    74 <DeleteIcon />
    75 </IconButton>
    76 </Box>
    77 )}
    78 />
    79 );
    80};
    81
    82export default Example;
    83

    Customize Row Actions Column

    Change Row Actions Display Column Options

    You can customize all column def options for the row actions column, including the column width, header text, and more using the displayColumnDefOptions prop.

    <MaterialReactTable
    columns={columns}
    data={data}
    displayColumnDefOptions={{
    'mrt-row-actions': {
    header: 'Change Account Settings', //change header text
    size: 300, //make actions column wider
    },
    }}
    renderRowActions={({ table }) => (
    <Box>
    <Button>Button 1</Button>
    <Button>Button 2</Button>
    <Button>Button 3</Button>
    </Box>
    )}
    />

    Position Row Actions Column

    You can position the row actions column to the left or right (first or last column) of the table using the positionActionsColumn prop. The default is as the first column.

    <MaterialReactTable
    columns={columns}
    data={data}
    positionActionsColumn="last"
    />