MRT logoMantine React Table

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.

const table = useMantineReactTable({
  columns,
  data,
  //note: each individual state must be mutually exclusive to `initial state` or `state`
  initialState: {
    // all the state options you can pass here
  },
  state: {
    // or here
  },
});
#
State Option
Type
Default Value
More Info Links
1{ [key: string]: MRT_FilterFn }
2Array<{id: string, value: unknown}>{}TanStack Table Filters Docs
3Array<string>[]TanStack Table Column Ordering Docs
4{ left: Array<string>, right: Array<string> }{ left: [], right: [] }TanStack Table Column Pinning Docs
5Record<string, number>{}TanStack Table Column Sizing Docs
6See TanStack Docs{}TanStack Table Column Sizing Docs
7Record<string, boolean>{}TanStack Table Column Visibility Docs
8MRT_Row
9'xs' | 'sm' | 'md' | 'lg' | 'xl''md'
10MRT_Column | null
11MRT_Row | null
12MRT_Cell
13MRT_Row
14Record<string, boolean> | boolean{}TanStack Table Expanding Docs
15anyTanStack Table Filtering Docs
16MRT_FilterFn
17Array<string>[]TanStack Table Grouping Docs
18MRT_Column | null
19MRT_Row | null
20booleanfalse
21booleanfalse
22booleanfalse
23{ pageIndex: number, pageSize: number }{ pageIndex: 0, pageSize: 10 }TanStack Table Pagination Docs
24Record<string, boolean>{}TanStack Table Row Selection Docs
25booleanfalse
26booleanfalse
27booleanfalse
28booleanfalse
29booleanfalse
30booleanfalse
31Array<{ id: string, desc: boolean }>[]TanStack Table Sorting Docs

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,
  type MRT_TableState,
} from 'mantine-react-table';
import { Anchor, Text } from '@mantine/core';
import { useMediaQuery } from '@mantine/hooks';
import { type StateOption, stateOptions } from './stateOptions';
import { InlineCodeHighlight } from '@mantine/code-highlight';

interface Props {
  onlyOptions?: Set<keyof MRT_TableState<StateOption>>;
}

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

  const columns = useMemo(
    () =>
      [
        {
          accessorKey: 'stateOption',
          enableClickToCopy: true,
          header: 'State Option',
          mantineCopyButtonProps: ({ cell }) => ({
            className: 'state-option',
            id: `${cell.getValue<string>()}-state-option`,
          }),
        },
        {
          accessorKey: 'type',
          header: 'Type',
          enableGlobalFilter: false,
          Cell: ({ cell }) => (
            <InlineCodeHighlight
              bg="transparent"
              language="typescript"
              code={cell.getValue<string>()}
            />
          ),
        },
        {
          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<StateOption>[],
    [],
  );

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

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

  const data = useMemo(() => {
    if (onlyOptions) {
      return stateOptions.filter(({ stateOption }) =>
        onlyOptions.has(stateOption),
      );
    }
    return stateOptions;
  }, [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: { description: false },
        density: 'xs',
        showGlobalFilter: true,
        sorting: [{ id: 'stateOption', desc: false }],
      }}
      mantineSearchTextInputProps={{
        placeholder: 'Search State Options',
        style: { minWidth: '18rem' },
        variant: 'filled',
      }}
      mantinePaperProps={{
        style: { marginBottom: '24px' },
        id: onlyOptions
          ? 'relevant-state-options-table'
          : 'state-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 StateOptionsTable;