Detail Panel Example
Material React Table has multiple types of "expanding" row features. In its simplest form, you can use the renderDetailPanel
option to render a component when a row is clicked. This is useful for showing additional information about a row, such as a list of nested data. Learn more in the Detail Panel Feature Guide.
Expand | ID | First Name | Middle Name | Last Name |
---|---|---|---|---|
1 | Dylan | Sprouse | Murray | |
2 | Raquel | Hakeem | Kohler | |
3 | Ervin | Kris | Reinger | |
4 | Brittany | Kathryn | McCullough | |
5 | Branson | John | Frami | |
10
1import { useMemo } from 'react';2import {3 MaterialReactTable,4 useMaterialReactTable,5 type MRT_ColumnDef,6} from 'material-react-table';7import { Box, Typography } from '@mui/material';8import { data, type Person } from './makeData';910const Example = () => {11 const columns = useMemo<MRT_ColumnDef<Person>[]>(12 //column definitions...34 );3536 const table = useMaterialReactTable({37 columns,38 data,39 enableExpandAll: false, //disable expand all button40 muiDetailPanelProps: () => ({41 sx: (theme) => ({42 backgroundColor:43 theme.palette.mode === 'dark'44 ? 'rgba(255,210,244,0.1)'45 : 'rgba(0,0,0,0.1)',46 }),47 }),48 //custom expand button rotation49 muiExpandButtonProps: ({ row, table }) => ({50 onClick: () => table.setExpanded({ [row.id]: !row.getIsExpanded() }), //only 1 detail panel open at a time51 sx: {52 transform: row.getIsExpanded() ? 'rotate(180deg)' : 'rotate(-90deg)',53 transition: 'transform 0.2s',54 },55 }),56 //conditionally render detail panel57 renderDetailPanel: ({ row }) =>58 row.original.address ? (59 <Box60 sx={{61 display: 'grid',62 margin: 'auto',63 gridTemplateColumns: '1fr 1fr',64 width: '100%',65 }}66 >67 <Typography>Address: {row.original.address}</Typography>68 <Typography>City: {row.original.city}</Typography>69 <Typography>State: {row.original.state}</Typography>70 <Typography>Country: {row.original.country}</Typography>71 </Box>72 ) : null,73 });7475 return <MaterialReactTable table={table} />;76};7778export default Example;79
View Extra Storybook Examples