State Options
Many of the state options you can pass here are the same as the ones you can pass to the useReactTable useTableInstance hook.
Here is a list of all the state options you can pass to initialState
or state
.
<MaterialReactTableinitialState={{// all the state options you can pass here}}state={{// or here}}/>
# | State Option | Type | Default Value | More Info Links | |
---|---|---|---|---|---|
1 |
| ||||
2 |
|
| TanStack Table Filters Docs | ||
3 |
|
| TanStack Table Column Ordering Docs | ||
4 |
|
| TanStack Table Column Pinning Docs | ||
5 |
|
| TanStack Table Column Sizing Docs | ||
6 |
|
| TanStack Table Column Sizing Docs | ||
7 |
|
| TanStack Table Column Visibility Docs | ||
8 |
|
| |||
9 |
| ||||
10 |
| ||||
11 |
| ||||
12 |
| ||||
13 |
|
| TanStack Table Expanding Docs | ||
14 |
| TanStack Table Filtering Docs | |||
15 |
| ||||
16 |
|
| TanStack Table Grouping Docs | ||
17 |
| ||||
18 |
| ||||
19 |
|
| |||
20 |
|
| |||
21 |
|
| TanStack Table Pagination Docs | ||
22 |
|
| TanStack Table Row Selection Docs | ||
23 |
|
| |||
24 |
|
| |||
25 |
|
| |||
26 |
|
| |||
27 |
|
| |||
28 |
|
| |||
29 |
|
| TanStack Table Sorting Docs | ||
Wanna see the source code for this table? Check it out down below!
1import React, { useEffect, useMemo, useState } from 'react';2import Link from 'next/link';3import {4 MaterialReactTable,5 type MRT_ColumnDef,6 type MRT_TableState,7} from 'material-react-table';8import { Link as MuiLink, Typography, useMediaQuery } from '@mui/material';9import { SampleCodeSnippet } from '../mdx/SampleCodeSnippet';10import { type StateRow, stateOptions } from './stateOptions';1112interface Props {13 onlyProps?: Set<keyof MRT_TableState>;14}1516const StateOptionsTable = ({ onlyProps }: Props) => {17 const isDesktop = useMediaQuery('(min-width: 1200px)');1819 const columns = useMemo<MRT_ColumnDef<StateRow>[]>(20 () => [21 {22 accessorKey: 'stateOption',23 enableClickToCopy: true,24 header: 'State Option',25 muiTableBodyCellCopyButtonProps: ({ cell }) => ({26 className: 'state-option',27 id: `${cell.getValue<string>()}-state-option`,28 }),29 },30 {31 accessorKey: 'type',32 header: 'Type',33 enableGlobalFilter: false,34 Cell: ({ cell }) => (35 <SampleCodeSnippet36 className="language-ts"37 enableCopyButton={false}38 style={{39 backgroundColor: 'transparent',40 fontSize: '0.9rem',41 margin: 0,42 padding: 0,43 minHeight: 'unset',44 }}45 >46 {cell.getValue<string>()}47 </SampleCodeSnippet>48 ),49 },50 {51 accessorKey: 'defaultValue',52 enableGlobalFilter: false,53 header: 'Default Value',54 Cell: ({ cell }) => (55 <SampleCodeSnippet56 className="language-js"57 enableCopyButton={false}58 style={{59 backgroundColor: 'transparent',60 fontSize: '0.9rem',61 margin: 0,62 padding: 0,63 minHeight: 'unset',64 }}65 >66 {cell.getValue<string>()}67 </SampleCodeSnippet>68 ),69 },70 {71 accessorKey: 'description',72 enableGlobalFilter: false,73 header: 'Description',74 },75 {76 accessorKey: 'link',77 disableFilters: true,78 enableGlobalFilter: false,79 header: 'More Info Links',80 Cell: ({ cell, row }) => (81 <Link href={cell.getValue<string>()} passHref legacyBehavior>82 <MuiLink83 target={84 cell.getValue<string>().startsWith('http')85 ? '_blank'86 : undefined87 }88 rel="noopener"89 >90 {row.original?.linkText}91 </MuiLink>92 </Link>93 ),94 },95 ],96 [],97 );9899 const [columnPinning, setColumnPinning] = useState({});100101 useEffect(() => {102 if (typeof window !== 'undefined') {103 if (isDesktop) {104 setColumnPinning({105 left: ['mrt-row-expand', 'mrt-row-numbers', 'stateOption'],106 right: ['link'],107 });108 } else {109 setColumnPinning({});110 }111 }112 }, [isDesktop]);113114 const data = useMemo(() => {115 if (onlyProps) {116 return stateOptions.filter(({ stateOption }) =>117 onlyProps.has(stateOption),118 );119 }120 return stateOptions;121 }, [onlyProps]);122123 return (124 <MaterialReactTable125 columns={columns}126 data={data}127 displayColumnDefOptions={{128 'mrt-row-numbers': {129 size: 10,130 },131 'mrt-row-expand': {132 size: 10,133 },134 }}135 enableColumnActions={!onlyProps}136 enableColumnFilterModes137 enablePagination={false}138 enablePinning139 enableRowNumbers140 enableBottomToolbar={false}141 enableTopToolbar={!onlyProps}142 initialState={{143 columnVisibility: { description: false },144 density: 'compact',145 showGlobalFilter: true,146 sorting: [{ id: 'stateOption', desc: false }],147 }}148 muiSearchTextFieldProps={{149 placeholder: 'Search State Options',150 sx: { minWidth: '18rem' },151 variant: 'outlined',152 }}153 muiTablePaperProps={{154 sx: { mb: '1.5rem' },155 id: onlyProps ? 'relevant-state-options-table' : 'state-options-table',156 }}157 positionGlobalFilter="left"158 renderDetailPanel={({ row }) => (159 <Typography160 color={row.original.description ? 'secondary.main' : 'text.secondary'}161 >162 {row.original.description || 'No Description Provided... Yet...'}163 </Typography>164 )}165 rowNumberMode="static"166 onColumnPinningChange={setColumnPinning}167 state={{ columnPinning }}168 />169 );170};171172export default StateOptionsTable;173