Table Instance APIs
Internally, Mantine React Table uses the
useReactTable
hook from TanStack Table to create a table instance that handles a majority of the logic and events and the state for the table.You can also access the table instance by consuming a
table
param from many of the callback functions in many of the props.const columns = useMemo(() => [{accessor: 'name',header: 'Name',Cell: ({ cell, table }) => <span onClick={() => table.{/* or maybe here */}}></span>,},], []);const table = useMantineReactTable({columns,data,renderTopToolbarCustomActions: ({ table }) => <Button onClick={() => table{/* or maybe here */}}>Click Me</Button>,});const someEventHandler = () => {table. //call any of the table instance methods here};return <MantineReactTable table={table} />;
NOTE: These are NOT the table options for Mantine React Table. These are just static methods on a table instance that you can use.
Wanna see the source code for this table? Check it out down below!
1import { useEffect, useMemo, useState } from 'react';2import Link from 'next/link';3import {4MantineReactTable,5type MRT_ColumnDef,6type MRT_TableInstance,7} from 'mantine-react-table';8import { Anchor, Text } from '@mantine/core';9import { useMediaQuery } from '@mantine/hooks';10import { SampleCodeSnippet } from '../mdx/SampleCodeSnippet';11import { type TableInstanceAPI, tableInstanceAPIs } from './tableInstanceAPIs';1213interface Props {14onlyOptions?: Set<keyof MRT_TableInstance<TableInstanceAPI>>;15}1617const TableInstanceAPIsTable = ({ onlyOptions }: Props) => {18const isDesktop = useMediaQuery('(min-width: 1200px)');1920const columns = useMemo(21() =>22[23{24accessorKey: 'tableInstanceAPI',25enableClickToCopy: true,26header: 'State Option',27mantineCopyButtonProps: ({ cell }) => ({28className: 'table-instance-api',29id: `${cell.getValue<string>()}-table-instance-api`,30}),31},32{33accessorKey: 'type',34header: 'Type',35enableGlobalFilter: false,36Cell: ({ cell }) => (37<SampleCodeSnippet language="typescript" noCopy>38{cell.getValue<string>()}39</SampleCodeSnippet>40),41},42{43accessorKey: 'link',44disableFilters: true,45enableGlobalFilter: false,46header: 'More Info Links',47Cell: ({ cell, row }) => (48<Link href={cell.getValue() as string} passHref legacyBehavior>49<Anchor50target={51(cell.getValue() as string).startsWith('http')52? '_blank'53: undefined54}55rel="noopener"56>57{row.original?.linkText}58</Anchor>59</Link>60),61},62] as MRT_ColumnDef<TableInstanceAPI>[],63[],64);6566const [columnPinning, setColumnPinning] = useState({});6768useEffect(() => {69if (typeof window !== 'undefined') {70if (isDesktop) {71setColumnPinning({72left: ['mrt-row-expand', 'mrt-row-numbers', 'tableInstanceAPI'],73right: ['link'],74});75} else {76setColumnPinning({});77}78}79}, [isDesktop]);8081const data = useMemo(() => {82if (onlyOptions) {83return tableInstanceAPIs.filter(({ tableInstanceAPI }) =>84onlyOptions.has(tableInstanceAPI),85);86}87return tableInstanceAPIs;88}, [onlyOptions]);8990return (91<MantineReactTable92columns={columns}93data={data}94displayColumnDefOptions={{95'mrt-row-numbers': {96size: 10,97},98'mrt-row-expand': {99size: 10,100},101}}102enableColumnActions={!onlyOptions}103enableColumnFilterModes104enablePagination={false}105enablePinning106enableRowNumbers107enableBottomToolbar={false}108enableTopToolbar={!onlyOptions}109initialState={{110columnVisibility: { description: false },111density: 'xs',112showGlobalFilter: true,113sorting: [{ id: 'tableInstanceAPI', desc: false }],114}}115mantineSearchTextInputProps={{116placeholder: 'Search Table APIs',117sx: { minWidth: '18rem' },118variant: 'filled',119}}120mantinePaperProps={{121sx: { marginBottom: '24px' },122id: onlyOptions123? 'relevant-table-instance-apis-table'124: 'table-instance-apis-table',125}}126positionGlobalFilter="left"127renderDetailPanel={({ row }) => (128<Text color={row.original.description ? 'teal' : 'gray'}>129{row.original.description || 'No Description Provided... Yet...'}130</Text>131)}132rowNumberMode="static"133onColumnPinningChange={setColumnPinning}134state={{ columnPinning }}135/>136);137};138139export default TableInstanceAPIsTable;