JGuang

Table

Table · Mantine Core

Preview
npm install @mantine/core@9.7.1 @mantine/hooks@9.7.1

Table

Install: npm install @mantine/core@9.7.1 @mantine/hooks@9.7.1

Version and compatibility

Pinned Mantine Core 9.7.1 requires React and React DOM ^19.2.0 and matching @mantine/hooks@9.7.1, from the installed npm package's peerDependencies. Do not force it into React 18 or another incompatible version. Explain upgrade impact and agree on a plan with the project owner; do not hide conflicts with --force/--legacy-peer-deps. The native Provider enables theme.respectReducedMotion and uses forceColorScheme for light/dark.

Use case

Present structured tabular data.

Native props used by this example

These props are extracted from the local typechecked JSX and grouped by their owning native component. This is not an exhaustive prop list; see pinned source signatures and inheritance below.

Component propExplanation
Table.stripedAlternate native table row styling.
Table.withTableBorderShow the outer table border.

Interaction and state checks

Current scenarios: Default. Check actual behavior after selecting supported disabled/error/read-only scenarios; components without those native states do not receive invented universal props. Verify keyboard focus and exits, then connect changed values through the native callback signature.

Business integration boundary

A styled table is not an automatic sorting/filtering/data-fetching engine. Keep native table structure and implement business data behavior separately.

Host setup

Install pinned @mantine/core and @mantine/hooks, import @mantine/core/styles.css at the entry and use MantineProvider. The example's theme/variant are JGuang-authored host props, not universal native component APIs; forceColorScheme synchronizes the app theme. Native implementation source is a reading reference: use npm exports rather than copying internal engines. This batch covers Core, not dates/charts/forms extension packages. Detailed upstream prose remains English.

Runnable usage

import { useState } from 'react';
import * as M from '@mantine/core';
import '@mantine/core/styles.css';


function ComponentPreview({ variant = 'Default' }: { variant?: string }) {

return <M.Table striped withTableBorder><M.Table.Thead><M.Table.Tr><M.Table.Th>Name</M.Table.Th><M.Table.Th>Type</M.Table.Th></M.Table.Tr></M.Table.Thead><M.Table.Tbody><M.Table.Tr><M.Table.Td>JGuang</M.Table.Td><M.Table.Td>Catalog</M.Table.Td></M.Table.Tr></M.Table.Tbody></M.Table>;
}
export default function Example({ variant = 'Default', theme = 'light' }: { variant?: string; theme?: 'light' | 'dark' }) {
return <M.MantineProvider forceColorScheme={theme} theme={{ respectReducedMotion: true }}><ComponentPreview variant={variant} /></M.MantineProvider>;
}

Preview states

Default

The example uses the native Mantine API. For supported input demos, change the local variant to Disabled, Invalid or Read only; these are example labels, not new component props. Keep the documented data, controlled values, stores and compound children when adapting the example.

Usage

Table data for all examples:

const elements = [
  { position: 6, mass: 12.011, symbol: 'C', name: 'Carbon' },
  { position: 7, mass: 14.007, symbol: 'N', name: 'Nitrogen' },
  { position: 39, mass: 88.906, symbol: 'Y', name: 'Yttrium' },
  { position: 56, mass: 137.33, symbol: 'Ba', name: 'Barium' },
  { position: 58, mass: 140.12, symbol: 'Ce', name: 'Cerium' },
];

data prop

You can use the data prop to automatically generate table rows from an array of React nodes. The data prop accepts an object with the following properties:

  • head – an array of React nodes (React.ReactNode[]) to render Table.Th in Table.Thead
  • foot – an array of React nodes (React.ReactNode[]) to render Table.Th in Table.Tfoot
  • body - an array of arrays of React nodes (React.ReactNode[][]) to render Table.Td in Table.Tbody
  • caption – a React node to render Table.Caption

Set stickyHeader to make the table header sticky. To customize the top position of the header, use the stickyHeaderOffset prop: it is useful when you have a fixed header in your application. For example, the Mantine documentation website has a fixed header with 60px height:

Spacing

To control spacing, use the horizontalSpacing and verticalSpacing props. Both props support spacing from theme.spacing and any valid CSS value to set cell padding:

Caption and tfoot

Table supports tfoot and caption elements. Set the captionSide prop (top or bottom) to change the caption position.

Striped and rows hover

Scroll container

To prevent viewport overflow, wrap Table with Table.ScrollContainer. The component accepts a minWidth prop which sets the minimum width below which the table will be scrollable.

By default, Table.ScrollContainer uses ScrollArea, you can change it to native scrollbars by setting type="native":

You can also set the maxHeight prop on Table.ScrollContainer to limit the table height:

Vertical variant

Set variant="vertical" to render the table with a vertical layout:

Tabular numbers

Set the tabularNums prop to render numbers in tabular style. It sets font-variant-numeric: tabular-nums which makes numbers have equal width. This is useful when you have columns with numbers and you want them to be aligned:

Example: Table virtualization

This example demonstrates how to use Table.ScrollContainer with @tanstack/react-virtual to efficiently render large datasets. Only the visible rows are rendered in the DOM, which significantly improves performance for tables with thousands of rows.

Example: Table with row selection

Source-backed parameter reference

Implementation signatures and types are generated from the pinned local source. Optional props, native inherited types, union branches and never exclusions are preserved. A forwardRef implementation's ref is a React reference, not an additional business prop.

Table(_props)
export type TableVariant = 'default' | 'vertical';

export type TableStylesNames =
  | 'table'
  | 'thead'
  | 'tbody'
  | 'tfoot'
  | 'tr'
  | 'th'
  | 'td'
  | 'caption';

export type TableCssVariables = {
  table:
    | '--table-layout'
    | '--table-border-color'
    | '--table-caption-side'
    | '--table-horizontal-spacing'
    | '--table-vertical-spacing'
    | '--table-striped-color'
    | '--table-highlight-on-hover-color'
    | '--table-sticky-header-offset';
};

export interface TableData {
  head?: React.ReactNode[];
  body?: React.ReactNode[][];
  foot?: React.ReactNode[];
  caption?: string;
}

export interface TableProps extends BoxProps, StylesApiProps<TableFactory>, ElementProps<'table'> {
  /** Value of `table-layout` style @default auto */
  layout?: React.CSSProperties['tableLayout'];

  /** Side of the `Table.Caption` @default bottom */
  captionSide?: 'top' | 'bottom';

  /** Color of table borders, key of `theme.colors` or any valid CSS color */
  borderColor?: MantineColor;

  /** If set, the table has the outer border @default false */
  withTableBorder?: boolean;

  /** If set, the table has borders between columns @default false */
  withColumnBorders?: boolean;

  /** If set, the table has borders between rows @default true */
  withRowBorders?: boolean;

  /** Horizontal cells spacing, key of `theme.spacing` or any valid CSS value for padding, numbers are converted to rem @default xs */
  horizontalSpacing?: MantineSpacing;

  /** Vertical cells spacing, key of `theme.spacing` or any valid CSS value for padding, numbers are converted to rem @default xs */
  verticalSpacing?: MantineSpacing;

  /** If set, every odd/even row background changes to `stripedColor`, if set to `true`, then `odd` value will be used @default false  */
  striped?: boolean | 'odd' | 'even';

  /** Background color of striped rows, key of `theme.colors` or any valid CSS color */
  stripedColor?: MantineColor;

  /** If set, table rows background changes to `highlightOnHoverColor` when hovered @default false */
  highlightOnHover?: boolean;

  /** Background color of table rows when hovered, key of `theme.colors` or any valid CSS color */
  highlightOnHoverColor?: MantineColor;

  /** Data used to generate table, ignored if `children` prop is set */
  data?: TableData;

  /** If set, `Table.Thead` is sticky @default false */
  stickyHeader?: boolean;

  /** Offset from top at which `Table.Thead` should become sticky @default 0 */
  stickyHeaderOffset?: number | string;

  /** If set, `font-variant-numeric: tabular-nums` style is applied @default false */
  tabularNums?: boolean;
}

export type TableFactory = Factory<{
  props: TableProps;
  ref: HTMLTableElement;
  stylesNames: TableStylesNames;
  vars: TableCssVariables;
  variant: TableVariant;
  staticComponents: {
    Thead: typeof TableThead;
    Tbody: typeof TableTbody;
    Tfoot: typeof TableTfoot;
    Td: typeof TableTd;
    Th: typeof TableTh;
    Tr: typeof TableTr;
    Caption: typeof TableCaption;
    ScrollContainer: typeof TableScrollContainer;
    DataRenderer: typeof TableDataRenderer;
  };
}>;

export type Mod = Record<string, any> | string;

export type BoxMod = Mod | Mod[] | BoxMod[];

export interface BoxProps extends MantineStyleProps {
  /** Class added to the root element, if applicable */
  className?: string | undefined;

  /** Inline style added to root component element, can subscribe to theme defined on MantineProvider */
  style?: MantineStyleProp;

  /** CSS variables defined on root component element */
  __vars?: CssVarsProp;

  /** `size` property passed down the HTML element */
  __size?: string;

  /** Breakpoint above which the component is hidden with `display: none` */
  hiddenFrom?: MantineBreakpoint;

  /** Breakpoint below which the component is hidden with `display: none` */
  visibleFrom?: MantineBreakpoint;

  /** Determines whether component should be hidden in light color scheme with `display: none` */
  lightHidden?: boolean;

  /** Determines whether component should be hidden in dark color scheme with `display: none` */
  darkHidden?: boolean;

  /** Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed */
  mod?: BoxMod;
}

export type ElementProps<
  ElementType extends React.ElementType,
  PropsToOmit extends string = never,
> = Omit<React.ComponentProps<ElementType>, 'style' | PropsToOmit>;

export interface CSSProperties extends React.CSSProperties {
  [key: string]: any;
}

type MantineStyle = CSSProperties | ((theme: MantineTheme) => CSSProperties);

export type MantineStyleProp = MantineStyle | MantineStyle[] | MantineStyleProp[] | undefined;

export type CssVariable = `--${string}`;

export type CssVariables<Variable extends string = CssVariable> = Partial<Record<Variable, string>>;

export type CssVars<Variable extends string = CssVariable> =
  | CssVariables<Variable>
  | ((theme: MantineTheme) => CssVariables<Variable>)
  | CssVars<Variable>[];

export type CssVarsProp<Variable extends string = CssVariable> =
  | CssVars<Variable>
  | CssVars<Variable>[];

Native and external types

External types remain defined by React or native dependencies, not manually expanded into guessed props. The installed version's TypeScript definitions are authoritative.

Factory<{
  props: TableProps;
  ref: HTMLTableElement;
  stylesNames: TableStylesNames;
  vars: TableCssVariables;
  variant: TableVariant;
  staticComponents: {
    Thead: typeof TableThead;
    Tbody: typeof TableTbody;
    Tfoot: typeof TableTfoot;
    Td: typeof TableTd;
    Th: typeof TableTh;
    Tr: typeof TableTr;
    Caption: typeof TableCaption;
    ScrollContainer: typeof TableScrollContainer;
    DataRenderer: typeof TableDataRenderer;
  };
}>
MantineStyleProps
React.CSSProperties
MantineTheme
Partial<Record<Variable, string>>
Record<Variable, string>
Variable
MantineBreakpoint
Record<string, any>
StylesApiProps<TableFactory>
React.ElementType
Omit<React.ComponentProps<ElementType>, 'style' | PropsToOmit>
React.ComponentProps<ElementType>
ElementType
PropsToOmit
MantineColor
MantineSpacing
React.ReactNode
HTMLTableElement