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 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 = ({ onlyProps }: Props) => {16 const isDesktop = useMediaQuery('(min-width: 1200px)');1718 const columns = useMemo<MRT_ColumnDef<StateRow>[]>(19 () => [20 {21 accessorKey: 'stateOption',22 enableClickToCopy: true,23 header: 'State Option',24 muiTableBodyCellCopyButtonProps: ({ cell }) => ({25 className: 'state-option',26 id: `${cell.getValue<string>()}-state-option`,27 }),28 },29 {30 accessorKey: 'type',31 header: 'Type',32 enableGlobalFilter: false,33 Cell: ({ cell }) => (34 <SampleCodeSnippet35 className="language-ts"36 enableCopyButton={false}37 style={{38 backgroundColor: 'transparent',39 fontSize: '0.9rem',40 margin: 0,41 padding: 0,42 minHeight: 'unset',43 }}44 >45 {cell.getValue<string>()}46 </SampleCodeSnippet>47 ),48 },49 {50 accessorKey: 'defaultValue',51 enableGlobalFilter: false,52 header: 'Default Value',53 Cell: ({ cell }) => (54 <SampleCodeSnippet55 className="language-js"56 enableCopyButton={false}57 style={{58 backgroundColor: 'transparent',59 fontSize: '0.9rem',60 margin: 0,61 padding: 0,62 minHeight: 'unset',63 }}64 >65 {cell.getValue<string>()}66 </SampleCodeSnippet>67 ),68 },69 {70 accessorKey: 'description',71 enableGlobalFilter: false,72 header: 'Description',73 },74 {75 accessorKey: 'link',76 disableFilters: true,77 enableGlobalFilter: false,78 header: 'More Info Links',79 Cell: ({ cell, row }) => (80 <Link href={cell.getValue<string>()} passHref legacyBehavior>81 <MuiLink82 target={83 cell.getValue<string>().startsWith('http')84 ? '_blank'85 : undefined86 }87 rel="noopener"88 >89 {row.original?.linkText}90 </MuiLink>91 </Link>92 ),93 },94 ],95 [],96 );9798 const [columnPinning, setColumnPinning] = useState({});99100 useEffect(() => {101 if (typeof window !== 'undefined') {102 if (isDesktop) {103 setColumnPinning({104 left: ['mrt-row-expand', 'mrt-row-numbers', 'stateOption'],105 right: ['link'],106 });107 } else {108 setColumnPinning({});109 }110 }111 }, [isDesktop]);112113 const data = useMemo(() => {114 if (onlyProps) {115 return stateOptions.filter(({ stateOption }) =>116 onlyProps.has(stateOption),117 );118 }119 return stateOptions;120 }, [onlyProps]);121122 return (123 <MaterialReactTable124 columns={columns}125 data={data}126 displayColumnDefOptions={{127 'mrt-row-numbers': {128 size: 10,129 },130 'mrt-row-expand': {131 size: 10,132 },133 }}134 enableColumnActions={!onlyProps}135 enableColumnFilterModes136 enablePagination={false}137 enablePinning138 enableRowNumbers139 enableBottomToolbar={false}140 enableTopToolbar={!onlyProps}141 initialState={{142 columnVisibility: { description: false },143 density: 'compact',144 showGlobalFilter: true,145 sorting: [{ id: 'stateOption', desc: false }],146 }}147 muiSearchTextFieldProps={{148 placeholder: 'Search State Options',149 sx: { minWidth: '18rem' },150 variant: 'outlined',151 }}152 muiTablePaperProps={{153 sx: { mb: '1.5rem' },154 id: onlyProps ? 'relevant-state-options-table' : 'state-options-table',155 }}156 positionGlobalFilter="left"157 renderDetailPanel={({ row }) => (158 <Typography159 color={row.original.description ? 'secondary.main' : 'text.secondary'}160 >161 {row.original.description || 'No Description Provided... Yet...'}162 </Typography>163 )}164 rowNumberMode="static"165 onColumnPinningChange={setColumnPinning}166 state={{ columnPinning }}167 />168 );169};170171export default StateOptionsTable;172