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 }) => ({50 sx: {51 transform: row.getIsExpanded() ? 'rotate(180deg)' : 'rotate(-90deg)',52 transition: 'transform 0.2s',53 },54 }),55 //conditionally render detail panel56 renderDetailPanel: ({ row }) =>57 row.original.address ? (58 <Box59 sx={{60 display: 'grid',61 margin: 'auto',62 gridTemplateColumns: '1fr 1fr',63 width: '100%',64 }}65 >66 <Typography>Address: {row.original.address}</Typography>67 <Typography>City: {row.original.city}</Typography>68 <Typography>State: {row.original.state}</Typography>69 <Typography>Country: {row.original.country}</Typography>70 </Box>71 ) : null,72 });7374 return <MaterialReactTable table={table} />;75};7677export default Example;78
View Extra Storybook Examples