Column Grouping Example
Material React Table has a few different UI options and behaviors for displaying grouped columns. See the Column Grouping Guide to learn more.
State | Gender | First Name | Last Name | Age | Salary | |
---|---|---|---|---|---|---|
Utah (1) | ||||||
Male (5) | ||||||
Danika | Rodriguez | 57 | 31404 | |||
Alfonzo | Abernathy | 40 | 53374 | |||
Antwan | Zieme | 21 | 56638 | |||
Kathryn | Langworth | 39 | 25720 | |||
Haylee | Price | 57 | 59047 | |||
Alaska (2) | ||||||
Male (4) | ||||||
Eloisa | Kohler | 31 | 45801 | |||
Kian | Hand | 56 | 81062 | |||
Michale | Collier | 59 | 75197 | |||
Eldridge | Stroman | 42 | 59594 | |||
Female (4) | ||||||
Loyce | Schmidt | 29 | 76295 | |||
Alvera | Balistreri | 25 | 79844 | |||
Kayden | Emard | 35 | 98252 | |||
Domingo | Bauch | 36 | 35159 | |||
Arizona (1) | ||||||
Male (1) |
20
1import { useMemo, useState } from 'react';2import {3 MaterialReactTable,4 useMaterialReactTable,5 type MRT_ColumnDef,6} from 'material-react-table';7import { data, type Person } from './makeData';8import {9 FormControl,10 FormControlLabel,11 FormLabel,12 Radio,13 RadioGroup,14 Stack,15} from '@mui/material';1617const Example = () => {18 const columns = useMemo<MRT_ColumnDef<Person>[]>(19 //column definitions...48 );4950 //demo state51 const [groupedColumnMode, setGroupedColumnMode] = useState<52 false | 'remove' | 'reorder'53 >('reorder'); //default is 'reorder5455 const table = useMaterialReactTable({56 columns,57 data,58 enableGrouping: true,59 groupedColumnMode,60 initialState: {61 expanded: true, //expand all groups by default62 grouping: ['state', 'gender'], //an array of columns to group by by default (can be multiple)63 pagination: { pageIndex: 0, pageSize: 20 },64 },65 muiTableContainerProps: { sx: { maxHeight: '800px' } },66 });6768 return (69 <Stack gap="1rem">70 <DemoRadioGroup71 groupedColumnMode={groupedColumnMode}72 setGroupedColumnMode={setGroupedColumnMode}73 />74 <MaterialReactTable table={table} />75 </Stack>76 );77};7879export default Example;8081//demo...117
View Extra Storybook Examples