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, { FC, useEffect, useMemo, useState } from 'react';2import Link from 'next/link';3import MaterialReactTable, {4 MRT_ColumnDef,5 MRT_TableState,6} from 'material-react-table';7import { Link as MuiLink, Typography, useMediaQuery } from '@mui/material';8import { SampleCodeSnippet } from '../mdx/SampleCodeSnippet';9import { StateRow, stateOptions } from './stateOptions';1011interface Props {12 onlyProps?: Set<keyof MRT_TableState>;13}1415const StateOptionsTable: FC<Props> = ({ onlyProps }) => {16 const isDesktop = useMediaQuery('(min-width: 1200px)');1718 const columns = useMemo(19 () =>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 Cell: ({ cell }) => cell.getValue<string>(),30 },31 {32 accessorKey: 'type',33 header: 'Type',34 enableGlobalFilter: false,35 Cell: ({ cell }) => (36 <SampleCodeSnippet37 className="language-ts"38 enableCopyButton={false}39 style={{40 backgroundColor: 'transparent',41 fontSize: '0.9rem',42 margin: 0,43 padding: 0,44 minHeight: 'unset',45 }}46 >47 {cell.getValue<string>()}48 </SampleCodeSnippet>49 ),50 },51 {52 accessorKey: 'defaultValue',53 enableGlobalFilter: false,54 header: 'Default Value',55 Cell: ({ cell }) => (56 <SampleCodeSnippet57 className="language-js"58 enableCopyButton={false}59 style={{60 backgroundColor: 'transparent',61 fontSize: '0.9rem',62 margin: 0,63 padding: 0,64 minHeight: 'unset',65 }}66 >67 {cell.getValue<string>()}68 </SampleCodeSnippet>69 ),70 },71 {72 accessorKey: 'description',73 enableGlobalFilter: false,74 header: 'Description',75 },76 {77 accessorKey: 'link',78 disableFilters: true,79 enableGlobalFilter: false,80 header: 'More Info Links',81 Cell: ({ cell, row }) => (82 <Link href={cell.getValue() as string} passHref legacyBehavior>83 <MuiLink84 target={85 (cell.getValue() as string).startsWith('http')86 ? '_blank'87 : undefined88 }89 rel="noreferrer"90 >91 {row.original?.linkText}92 </MuiLink>93 </Link>94 ),95 },96 ] as MRT_ColumnDef<StateRow>[],97 [],98 );99100 const [columnPinning, setColumnPinning] = useState({});101102 useEffect(() => {103 if (typeof window !== 'undefined') {104 if (isDesktop) {105 setColumnPinning({106 left: ['mrt-row-expand', 'mrt-row-numbers', 'stateOption'],107 right: ['link'],108 });109 } else {110 setColumnPinning({});111 }112 }113 }, [isDesktop]);114115 const data = useMemo(() => {116 if (onlyProps) {117 return stateOptions.filter(({ stateOption }) =>118 onlyProps.has(stateOption),119 );120 }121 return stateOptions;122 }, [onlyProps]);123124 return (125 <MaterialReactTable126 columns={columns}127 data={data}128 displayColumnDefOptions={{129 'mrt-row-numbers': {130 size: 10,131 },132 'mrt-row-expand': {133 size: 10,134 },135 }}136 enableColumnActions={!onlyProps}137 enableColumnFilterModes138 enablePagination={false}139 enablePinning140 enableRowNumbers141 enableBottomToolbar={false}142 enableTopToolbar={!onlyProps}143 initialState={{144 columnVisibility: { description: false },145 density: 'compact',146 showGlobalFilter: true,147 sorting: [{ id: 'stateOption', desc: false }],148 }}149 muiSearchTextFieldProps={{150 placeholder: 'Search State Options',151 sx: { minWidth: '18rem' },152 variant: 'outlined',153 }}154 muiTablePaperProps={{155 sx: { mb: '1.5rem' },156 id: onlyProps ? 'relevant-state-options-table' : 'state-options-table',157 }}158 positionGlobalFilter="left"159 renderDetailPanel={({ row }) => (160 <Typography161 color={row.original.description ? 'secondary.main' : 'text.secondary'}162 >163 {row.original.description || 'No Description Provided... Yet...'}164 </Typography>165 )}166 rowNumberMode="static"167 onColumnPinningChange={setColumnPinning}168 state={{ columnPinning }}169 />170 );171};172173export default StateOptionsTable;174