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
10boolean
11booleanMRT Click to Copy Docs
12booleanMRT Column Actions Docs
13boolean
14booleanMRT Column Filtering Docs
15booleanMRT Column Filtering Docs
16boolean
17boolean | (row: MRT_Row<TData>) => boolean
18boolean
19boolean
20boolean
21boolean
22booleantrue
23boolean
24boolean
25boolean
26({ column, header, table }) => ReactNodeMRT Column Filtering Docs
27MRT_FilterFn'fuzzy'
28MRT_FilterTooltipValueFn
29'text' | 'autocomplete' | 'select' | 'multi-select' | 'range' | 'range-slider' | 'checkbox' | 'date' | 'date-range''text'
30ReactNode | ({ column, footer, table }) => ReactNodeMRT Data Columns Docs
31(row: TData) => any)TanStack Table Grouping Docs
32({ cell, column, row, table }) => ReactNode
33ReactNode | (({ column, header, table }) => ReactNode)MRT Data Columns Docs
34stringTanStack Table ColumnDef Docs
35stringTanStack Table ColumnDef Docs
36booleanfalse
37ActionIconProps | ({ column, table }) => ActionIconPropsMantine ActionIcon API
38ActionIconProps | ({ column, table }) => ActionIconPropsMantine ActionIcon API
39UnstyledButtonProps | ({ cell, column, row, table }) => UnstyledButtonPropsMantine UnstyledButton API
40SelectProps | ({ cell, column, row, table }) => SelectPropsMantine Select Docs
41TextInputProps | ({ cell, column, row, table }) => TextInputPropsMantine TextInput API
42AutocompleteProps | ({ column, table, rangeFilterIndex}) => AutocompletePropsMantine Autocomplete Docs
43CheckboxProps | ({ column, table }) => CheckboxPropsMantine Checkbox Props
44DateInputProps | ({ table, column, rangeFilterIndex }) => DateInputPropsMantine DateInput Docs
45MultiSelectProps | ({ column, table }) => MultiSelectPropsMantine MultiSelect Docs
46RangeSliderProps | ({ column, table }) => RangeSliderPropsMantine Slider Docs
47SelectProps | ({ column, table }) => SelectPropsMantine Select Docs
48TextInputProps | ({ column, rangeFilterIndex, table }) => TextInputPropsMantine TextInput Docs
49BoxProps | ({ cell, table }) => BoxPropsMantine Box API
50BoxProps | ({ column, table }) => BoxPropsMantine Box API
51BoxProps | ({ column, table }) => BoxPropsMantine Box API
52number1000
53any{}
54number40
55
56
57number180
58boolean
59SortingFnOption
60false | 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;