Row Instance APIs
Every row in the table has an associated row instance that can be accessed in many of the callback props that you can use to access a row's information and methods.
You can access and use a
row
object in quite a few places, but here are some of the most common:const columns = [{accessorKey: 'salary',header: 'Salary',//you can access a row instance in column definition option callbacks like thismantineEditTextInputProps: ({ row }) => ({disabled: row.original.employmentStatus === 'Retired',}),//or in the component override callbacks like thisCell: ({ cell, row }) => (<div>{row.original.employmentStatus === 'Retired'? 'Retired': cell.getValue()}</div>),},];const table = useMantineReactTable({columns,data,mantineSelectCheckboxProps: ({ row }) => ({disabled: row.original.isAccountActive === false,}),renderDetailPanel: ({ row }) => (<div><span>First Name: {row.original.firstName}</span><span>Last Name: {row.original.lastName}</span></div>),});return <MantineReactTable table={table} />;
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_Row,7} from 'mantine-react-table';8import { Anchor, Text } from '@mantine/core';9import { useMediaQuery } from '@mantine/hooks';10import { SampleCodeSnippet } from '../mdx/SampleCodeSnippet';11import { type RowInstanceAPI, rowInstanceAPIs } from './rowInstanceAPIs';1213interface Props {14onlyOptions?: Set<keyof MRT_Row<RowInstanceAPI>>;15}1617const RowInstanceAPIsTable = ({ onlyOptions }: Props) => {18const isDesktop = useMediaQuery('(min-width: 1200px)');1920const columns = useMemo(21() =>22[23{24accessorKey: 'rowInstanceAPI',25enableClickToCopy: true,26header: 'State Option',27mantineCopyButtonProps: ({ cell }) => ({28className: 'row-instance-api',29id: `${cell.getValue<string>()}-row-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<RowInstanceAPI>[],63[],64);6566const [columnPinning, setColumnPinning] = useState({});6768useEffect(() => {69if (typeof window !== 'undefined') {70if (isDesktop) {71setColumnPinning({72left: ['mrt-row-expand', 'mrt-row-numbers', 'rowInstanceAPI'],73right: ['link'],74});75} else {76setColumnPinning({});77}78}79}, [isDesktop]);8081const data = useMemo(() => {82if (onlyOptions) {83return rowInstanceAPIs.filter(({ rowInstanceAPI }) =>84onlyOptions.has(rowInstanceAPI),85);86}87return rowInstanceAPIs;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: 'rowInstanceAPI', desc: false }],114}}115mantineSearchTextInputProps={{116placeholder: 'Search Row APIs',117sx: { minWidth: '18rem' },118variant: 'filled',119}}120mantinePaperProps={{121sx: { marginBottom: '24px' },122id: onlyOptions123? 'relevant-row-instance-apis-table'124: 'row-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 RowInstanceAPIsTable;