MRT logoMantine React Table

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
    },
  ],
  [],
);

const table = useMantineReactTable({ columns, data });

return <MantineReactTable table={table} />;
#
Column Option
Type
Default Value
More Info Links
1(originalRow: TData) => anyMRT Data Columns Docs
2string & keyof TDataMRT Data Columns Docs
3({ cell, column, row, table }) => ReactNode
4'count'TanStack Table Grouping Docs
5({ cell, column, renderedCellValue, row, table }) => ReactNodeMRT Data Columns Docs
6Array<string>
7Array<MRT_ColumnDef<TData>>
8({ cell, column, row, table }) => ReactNodeMRT Editing Docs
9'select' | 'text' | 'multi-select''text'MRT Editing Docs
10booleanMRT Click to Copy Docs
11booleanMRT Column Actions Docs
12boolean
13booleanMRT Column Filtering Docs
14booleanMRT Column Filtering Docs
15boolean
16boolean | (row: MRT_Row<TData>) => boolean
17boolean
18boolean
19boolean
20boolean
21booleantrue
22boolean
23boolean
24boolean
25({ column, header, table }) => ReactNodeMRT Column Filtering Docs
26MRT_FilterFn'fuzzy'
27'text' | 'autocomplete' | 'select' | 'multi-select' | 'range' | 'range-slider' | 'checkbox' | 'date' | 'date-range''text'
28ReactNode | ({ column, footer, table }) => ReactNodeMRT Data Columns Docs
29(row: TData) => any)TanStack Table Grouping Docs
30({ cell, column, row, table }) => ReactNode
31ReactNode | (({ column, header, table }) => ReactNode)MRT Data Columns Docs
32stringTanStack Table ColumnDef Docs
33stringTanStack Table ColumnDef Docs
34booleanfalse
35ActionIconProps | ({ column, table }) => ActionIconPropsMantine ActionIcon API
36ActionIconProps | ({ column, table }) => ActionIconPropsMantine ActionIcon API
37UnstyledButtonProps | ({ cell, column, row, table }) => UnstyledButtonPropsMantine UnstyledButton API
38SelectProps | ({ cell, column, row, table }) => SelectPropsMantine Select Docs
39TextInputProps | ({ cell, column, row, table }) => TextInputPropsMantine TextInput API
40AutocompleteProps | ({ column, table, rangeFilterIndex}) => AutocompletePropsMantine Autocomplete Docs
41CheckboxProps | ({ column, table }) => CheckboxPropsMantine Checkbox Props
42DateInputProps | ({ table, column, rangeFilterIndex }) => DateInputPropsMantine DateInput Docs
43MultiSelectProps | ({ column, table }) => MultiSelectPropsMantine MultiSelect Docs
44RangeSliderProps | ({ column, table }) => RangeSliderPropsMantine Slider Docs
45SelectProps | ({ column, table }) => SelectPropsMantine Select Docs
46TextInputProps | ({ column, rangeFilterIndex, table }) => TextInputPropsMantine TextInput Docs
47BoxProps | ({ cell, table }) => BoxPropsMantine Box API
48BoxProps | ({ column, table }) => BoxPropsMantine Box API
49BoxProps | ({ column, table }) => BoxPropsMantine Box API
50number1000
51any{}
52number40
53
54
55number180
56boolean
57SortingFnOption
58false | 1 | -1

Wanna see the source code for this table? Check it out down below!

import { useEffect, useMemo, useState } from 'react';
import Link from 'next/link';
import { MantineReactTable, type MRT_ColumnDef } from 'mantine-react-table';
import { Anchor, Text } from '@mantine/core';
import { useMediaQuery } from '@mantine/hooks';
import { type ColumnOption, columnOptions } from './columnOptions';
import { getPrimaryColor } from 'mantine-react-table';
import { InlineCodeHighlight } from '@mantine/code-highlight';

interface Props {
  onlyOptions?: Set<keyof MRT_ColumnDef<ColumnOption>>;
}

const ColumnOptionsTable = ({ onlyOptions }: Props) => {
  const isDesktop = useMediaQuery('(min-width: 1200px)');

  const columns = useMemo(
    () =>
      [
        {
          accessorKey: 'columnOption',
          enableClickToCopy: true,
          header: 'Column Option',
          mantineCopyButtonProps: ({ cell, row }) => ({
            className: 'column-option',
            id: `${cell.getValue<string>()}-column-option`,
          }),
          Cell: ({ renderedCellValue, row }) =>
            row.original?.required ? (
              <Text
                component="strong"
                style={(theme) => ({
                  color: getPrimaryColor(theme),
                })}
              >
                {renderedCellValue}*
              </Text>
            ) : (
              renderedCellValue
            ),
        },
        {
          accessorKey: 'type',
          header: 'Type',
          enableGlobalFilter: false,
          Cell: ({ cell }) => (
            <InlineCodeHighlight
              bg="transparent"
              language="typescript"
              code={cell.getValue<string>()}
            />
          ),
        },
        {
          accessorKey: 'required',
          enableGlobalFilter: false,
          header: 'Required',
        },
        {
          accessorKey: 'defaultValue',
          enableGlobalFilter: false,
          header: 'Default Value',
          Cell: ({ cell }) => (
            <InlineCodeHighlight
              bg="transparent"
              language="typescript"
              code={cell.getValue<string>()}
            />
          ),
        },
        {
          accessorKey: 'description',
          enableGlobalFilter: false,
          header: 'Description',
        },
        {
          accessorKey: 'link',
          disableFilters: true,
          enableGlobalFilter: false,
          header: 'More Info Links',
          Cell: ({ cell, row }) => (
            <Link href={cell.getValue() as string} passHref legacyBehavior>
              <Anchor
                target={
                  (cell.getValue() as string).startsWith('http')
                    ? '_blank'
                    : undefined
                }
                rel="noopener"
              >
                {row.original?.linkText}
              </Anchor>
            </Link>
          ),
        },
      ] as MRT_ColumnDef<ColumnOption>[],
    [],
  );

  const [columnPinning, setColumnPinning] = useState({});

  useEffect(() => {
    if (typeof window !== 'undefined') {
      if (isDesktop) {
        setColumnPinning({
          left: ['mrt-row-expand', 'mrt-row-numbers', 'columnOption'],
          right: ['link'],
        });
      } else {
        setColumnPinning({});
      }
    }
  }, [isDesktop]);

  const data = useMemo(() => {
    if (onlyOptions) {
      return columnOptions.filter(({ columnOption }) =>
        onlyOptions.has(columnOption),
      );
    }
    return columnOptions;
  }, [onlyOptions]);

  return (
    <MantineReactTable
      columns={columns}
      data={data}
      displayColumnDefOptions={{
        'mrt-row-numbers': {
          size: 10,
        },
        'mrt-row-expand': {
          size: 10,
        },
      }}
      enableColumnActions={!onlyOptions}
      enableColumnFilterModes
      enablePagination={false}
      enableColumnPinning
      enableRowNumbers
      enableBottomToolbar={false}
      enableTopToolbar={!onlyOptions}
      initialState={{
        columnVisibility: { required: false, description: false },
        density: 'xs',
        showGlobalFilter: true,
        sorting: [{ id: 'columnOption', desc: false }],
      }}
      mantineSearchTextInputProps={{
        placeholder: 'Search Column Options',
        style: { minWidth: '18rem' },
        variant: 'filled',
      }}
      mantinePaperProps={{
        style: { marginBottom: '24px' },
        id: onlyOptions
          ? 'relevant-column-options-table'
          : 'column-options-table',
      }}
      positionGlobalFilter="left"
      renderDetailPanel={({ row }) => (
        <Text color={row.original.description ? 'teal' : 'gray'}>
          {row.original.description || 'No Description Provided... Yet...'}
        </Text>
      )}
      rowNumberDisplayMode="static"
      onColumnPinningChange={setColumnPinning}
      state={{ columnPinning }}
    />
  );
};

export default ColumnOptionsTable;