Column Pinning Example
Material React Table easily has an easy to enable column pinning feature. Columns can be pinned to the left or right of the table, and the will be frozen in place while the rest of the table scrolls horizontally. See the Column Pinning Feature Guide for more information.
Actions | State | ID | First Name | Middle Name | Last Name | Address | Country | City |
---|---|---|---|---|---|---|---|---|
Kentucky | 1 | Dylan | Sprouse | Murray | 261 Erdman Ford | United States | East Daphne | |
Ohio | 2 | Raquel | Hakeem | Kohler | 769 Dominic Grove | United States | Columbus | |
West Virginia | 3 | Ervin | Kris | Reinger | 566 Brakus Inlet | United States | South Linda | |
Nebraska | 4 | Brittany | Kathryn | McCullough | 722 Emie Stream | United States | Lincoln | |
South Carolina | 5 | Branson | John | Frami | 32188 Larkin Turnpike | United States | Charleston | |
British Columbia | 6 | Brandon | Joe | Kutch | 5660 Kuhn Village | Canada | Vancouver |
10
1-6 of 6
1import { useMemo } from 'react';2import { MaterialReactTable, type MRT_ColumnDef } from 'material-react-table';3import { data, type Person } from './makeData';4import { MenuItem } from '@mui/material';56const Example = () => {7 const columns = useMemo<MRT_ColumnDef<Person>[]>(8 () => [9 {10 accessorKey: 'id',11 enableColumnPinning: false, //disable column pinning for this column12 header: 'ID',13 size: 50,14 },15 {16 accessorKey: 'firstName',17 header: 'First Name',18 },19 {20 accessorKey: 'middleName',21 header: 'Middle Name',22 },23 {24 accessorKey: 'lastName',25 header: 'Last Name',26 },27 {28 accessorKey: 'address',29 header: 'Address',30 size: 300,31 },32 {33 accessorKey: 'city', //this column gets pinned to the right by default because of the initial state,34 header: 'City',35 },36 {37 accessorKey: 'state', //this column gets pinned left by default because of the the initial state,38 header: 'State',39 },40 {41 accessorKey: 'country',42 header: 'Country',43 },44 ],45 [],46 );4748 return (49 <MaterialReactTable50 columns={columns}51 data={data}52 enableColumnPinning53 enableRowActions54 renderRowActionMenuItems={() => [55 <MenuItem key="action">Action</MenuItem>,56 ]}57 initialState={{58 columnPinning: { left: ['mrt-row-actions', 'state'], right: ['city'] },59 }}60 />61 );62};6364export default Example;65
View Extra Storybook Examples