Column Options
Many of the column options you can pass here are the same as the ones that you can pass to the useReactTable ColumnDefs
Here is a list of all the column options you can specify in a column
definition.
const columns = useMemo(() => [{accessorKey: 'name',header: 'Name',// All of the options you can specify here},],[],);return <MaterialReactTable columns={columns} data={data} />;
# | Column Option 2 | Type | Default Value | More Info Links | |
---|---|---|---|---|---|
1 |
| TanStack Table ColumnDef Docs | |||
2 |
| MRT Data Columns Docs | |||
3 |
| MRT Data Columns Docs | |||
4 |
| ||||
5 |
| TanStack Table Grouping Docs | |||
6 |
| MRT Data Columns Docs | |||
7 |
| ||||
8 |
| ||||
9 |
| MRT Editing Docs | |||
10 |
| ||||
11 |
|
| |||
12 |
| MRT Click to Copy Docs | |||
13 |
| MRT Column Actions Docs | |||
14 |
| ||||
15 |
| MRT Column Filtering Docs | |||
16 |
| MRT Column Filtering Docs | |||
17 |
| ||||
18 |
| ||||
19 |
| MRT Column Filtering Docs | |||
20 |
| ||||
21 |
| ||||
22 |
| ||||
23 |
|
| |||
24 |
| ||||
25 |
| ||||
26 |
| ||||
27 |
| MRT Column Filtering Docs | |||
28 |
|
| |||
29 |
| ||||
30 |
|
| |||
31 |
| MRT Data Columns Docs | |||
32 |
| TanStack Table Grouping Docs | |||
33 |
| ||||
34 |
| MRT Data Columns Docs | |||
35 |
| TanStack Table ColumnDef Docs | |||
36 |
|
| |||
37 |
|
| |||
38 |
|
| |||
39 |
|
| |||
40 |
| Material UI Button API | |||
41 |
| Material UI TextField API | |||
42 |
| Material UI TableCell API | |||
43 |
| Material UI TableCell API | |||
44 |
| Material UI IconButton API | |||
45 |
| Material UI IconButton API | |||
46 |
| Material UI Checkbox Props | |||
47 |
| Material UI Slider Props | |||
48 |
| Material UI TextField Props | |||
49 |
| Material UI TableCell API | |||
50 |
| ||||
51 |
| ||||
52 | |||||
53 |
|
| |||
54 |
| ||||
55 |
| ||||
56 |
| ||||
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, type MRT_ColumnDef } from 'material-react-table';4import {5 Link as MuiLink,6 Typography,7 useMediaQuery,8 useTheme,9} from '@mui/material';10import { SampleCodeSnippet } from '../mdx/SampleCodeSnippet';11import { type ColumnOption, columnOptions } from './columnOptions';1213interface Props {14 onlyProps?: Set<keyof MRT_ColumnDef>;15}1617const ColumnOptionsTable = ({ onlyProps }: Props) => {18 const theme = useTheme();19 const isDesktop = useMediaQuery('(min-width: 1200px)');2021 const columns = useMemo<MRT_ColumnDef<ColumnOption>[]>(22 () => [23 {24 accessorKey: 'columnOption',25 enableClickToCopy: true,26 header: 'Column Option',27 muiTableBodyCellCopyButtonProps: ({ cell }) => ({28 className: 'column-option',29 id: `${cell.getValue<string>()}-column-option`,30 }),31 Cell: ({ renderedCellValue, row }) =>32 row.original?.required ? (33 <strong style={{ color: theme.palette.primary.dark }}>34 {renderedCellValue}*35 </strong>36 ) : (37 renderedCellValue38 ),39 },40 {41 accessorKey: 'type',42 header: 'Type',43 enableGlobalFilter: false,44 Cell: ({ cell }) => (45 <SampleCodeSnippet46 className="language-ts"47 enableCopyButton={false}48 style={{49 backgroundColor: 'transparent',50 fontSize: '0.9rem',51 margin: 0,52 padding: 0,53 minHeight: 'unset',54 }}55 >56 {cell.getValue<string>()}57 </SampleCodeSnippet>58 ),59 },60 {61 accessorKey: 'required',62 enableGlobalFilter: false,63 header: 'Required',64 },65 {66 accessorKey: 'defaultValue',67 enableGlobalFilter: false,68 header: 'Default Value',69 Cell: ({ cell }) => (70 <SampleCodeSnippet71 className="language-js"72 enableCopyButton={false}73 style={{74 backgroundColor: 'transparent',75 fontSize: '0.9rem',76 margin: 0,77 padding: 0,78 minHeight: 'unset',79 }}80 >81 {cell.getValue<string>()}82 </SampleCodeSnippet>83 ),84 },85 {86 accessorKey: 'description',87 enableGlobalFilter: false,88 header: 'Description',89 },90 {91 accessorKey: 'link',92 disableFilters: true,93 enableGlobalFilter: false,94 header: 'More Info Links',95 Cell: ({ cell, row }) => (96 <Link href={cell.getValue<string>()} passHref legacyBehavior>97 <MuiLink98 target={99 cell.getValue<string>().startsWith('http')100 ? '_blank'101 : undefined102 }103 rel="noopener"104 >105 {row.original?.linkText}106 </MuiLink>107 </Link>108 ),109 },110 ],111 [theme],112 );113114 const [columnPinning, setColumnPinning] = useState({});115116 useEffect(() => {117 if (typeof window !== 'undefined') {118 if (isDesktop) {119 setColumnPinning({120 left: ['mrt-row-expand', 'mrt-row-numbers', 'columnOption'],121 right: ['link'],122 });123 } else {124 setColumnPinning({});125 }126 }127 }, [isDesktop]);128129 const data = useMemo(() => {130 if (onlyProps) {131 return columnOptions.filter(({ columnOption }) =>132 onlyProps.has(columnOption),133 );134 }135 return columnOptions;136 }, [onlyProps]);137138 return (139 <MaterialReactTable140 columns={columns}141 data={data}142 displayColumnDefOptions={{143 'mrt-row-numbers': {144 size: 10,145 },146 'mrt-row-expand': {147 size: 10,148 },149 }}150 enableColumnActions={!onlyProps}151 enableColumnFilterModes152 enablePagination={false}153 enablePinning154 enableRowNumbers155 enableBottomToolbar={false}156 enableTopToolbar={!onlyProps}157 initialState={{158 columnVisibility: { required: false, description: false },159 density: 'compact',160 showGlobalFilter: true,161 sorting: [162 { id: 'required', desc: true },163 { id: 'columnOption', desc: false },164 ],165 }}166 muiSearchTextFieldProps={{167 placeholder: 'Search Column Options',168 sx: { minWidth: '18rem' },169 variant: 'outlined',170 }}171 muiTablePaperProps={{172 sx: { mb: '1.5rem' },173 id: onlyProps174 ? 'relevant-column-options-table'175 : 'column-options-table',176 }}177 positionGlobalFilter="left"178 renderDetailPanel={({ row }) => (179 <Typography180 color={row.original.description ? 'secondary.main' : 'text.secondary'}181 >182 {row.original.description || 'No Description Provided... Yet...'}183 </Typography>184 )}185 rowNumberMode="static"186 onColumnPinningChange={setColumnPinning}187 state={{ columnPinning }}188 />189 );190};191192export default ColumnOptionsTable;193