Customization

DataGrid Styles API, CSS variables, compound components

Frame

By default, the grid has a border around the toolbar, the table and the footer. Use radius to change its border radius and withTableBorder={false} to remove the border. borderColor accepts a key of theme.colors or any valid CSS color:

First Name
Last Name
Department
Salary
AliceJohnsonEngineering95000
BobSmithMarketing72000
CarolWilliamsSales68000
DavidBrownHR65000
EvaDavisFinance88000
Radius
import { DataGrid } from '@mantine/data-grid';
import { employees } from './data';
const columns = [
  { accessorKey: 'firstName', header: 'First Name' },
  { accessorKey: 'lastName', header: 'Last Name' },
  { accessorKey: 'department', header: 'Department' },
  { accessorKey: 'salary', header: 'Salary', meta: { align: 'end' as const } },
];

function Demo() {
  return (
    <DataGrid
      data={employees.slice(0, 5)}
      columns={columns}
      radius="md"
    />
  );
}

Separators

Use these DataGrid props to style rows and separators:

interface DataGridProps<TData extends RowData = any> {
  /** Draw borders between rows. Use 'subtle' for a lighter border. */
  withRowBorders?: boolean | 'subtle';

  /** Draw borders between columns. Use 'data' to skip utility columns. */
  withColumnBorders?: boolean | 'data';

  /** Alternate the row background. */
  striped?: boolean | 'odd' | 'even';
  stripedColor?: MantineColor;

  /** Highlight rows on hover. */
  highlightOnHover?: boolean;
  highlightOnHoverColor?: MantineColor;

  /** Use tabular figures in every cell. */
  tabularNums?: boolean;
}

To display stripes without row borders, set striped and withRowBorders={false}:

Default rules

First Name
Last Name
Department
Salary
AliceJohnsonEngineering95000
BobSmithMarketing72000
CarolWilliamsSales68000
DavidBrownHR65000

Subtle rules

First Name
Last Name
Department
Salary
AliceJohnsonEngineering95000
BobSmithMarketing72000
CarolWilliamsSales68000
DavidBrownHR65000

Stripes without rules

First Name
Last Name
Department
Salary
AliceJohnsonEngineering95000
BobSmithMarketing72000
CarolWilliamsSales68000
DavidBrownHR65000

Column borders between data columns

First Name
Last Name
Department
Salary
AliceJohnsonEngineering95000
BobSmithMarketing72000
CarolWilliamsSales68000
DavidBrownHR65000

Every separator

First Name
Last Name
Department
Salary
AliceJohnsonEngineering95000
BobSmithMarketing72000
CarolWilliamsSales68000
DavidBrownHR65000
import { Stack, Text } from '@mantine/core';
import { DataGrid, DataGridProps } from '@mantine/data-grid';
import { employees } from './data';

const columns = [
  { accessorKey: 'firstName', header: 'First Name' },
  { accessorKey: 'lastName', header: 'Last Name' },
  { accessorKey: 'department', header: 'Department' },
  { accessorKey: 'salary', header: 'Salary', meta: { align: 'end' as const } },
];

const looks: { label: string; props: Partial<DataGridProps> }[] = [
  { label: 'Default rules', props: {} },
  { label: 'Subtle rules', props: { withRowBorders: 'subtle' } },
  { label: 'Stripes without rules', props: { striped: true, withRowBorders: false } },
  { label: 'Column borders between data columns', props: { withColumnBorders: 'data' } },
  { label: 'Every separator', props: { striped: 'even', withColumnBorders: true } },
];

function Demo() {
  return (
    <Stack gap="lg">
      {looks.map(({ label, props }) => (
        <div key={label}>
          <Text size="sm" fw={500} mb="xs">
            {label}
          </Text>
          <DataGrid
            data={employees.slice(0, 4)}
            columns={columns}
            highlightOnHover
            {...props}
          />
        </div>
      ))}
    </Stack>
  );
}

Example with custom stripe and hover colors:

First Name
Last Name
Email
Department
Salary
AliceJohnsonalice.johnson@example.comEngineering95000
BobSmithbob.smith@example.comMarketing72000
CarolWilliamscarol.williams@example.comSales68000
DavidBrowndavid.brown@example.comHR65000
EvaDaviseva.davis@example.comFinance88000
FrankMillerfrank.miller@example.comEngineering102000
GraceWilsongrace.wilson@example.comMarketing76000
HenryTaylorhenry.taylor@example.comSales71000
IreneAndersonirene.anderson@example.comEngineering97000
JamesThomasjames.thomas@example.comFinance91000
KarenJacksonkaren.jackson@example.comHR63000
LeoWhiteleo.white@example.comEngineering110000
MiaHarrismia.harris@example.comSales74000
NathanMartinnathan.martin@example.comMarketing69000
OliviaGarciaolivia.garcia@example.comFinance85000
PatrickMartinezpatrick.martinez@example.comEngineering99000
QuinnRobinsonquinn.robinson@example.comHR67000
RachelClarkrachel.clark@example.comSales73000
import { DataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  return (
    <DataGrid
      data={employees}
      striped
      highlightOnHover
      withRowBorders={false}
      stripedColor="var(--mantine-color-blue-light)"
      highlightOnHoverColor="var(--mantine-color-blue-light-hover)"
      columns={[
        { accessorKey: 'firstName', header: 'First Name' },
        { accessorKey: 'lastName', header: 'Last Name' },
        { accessorKey: 'email', header: 'Email', size: 220 },
        { accessorKey: 'department', header: 'Department' },
        { accessorKey: 'salary', header: 'Salary', meta: { align: 'end' } },
      ]}
    />
  );
}

Size

size is a useDataGrid option, sm by default. It controls the font size, row height, cell padding and the size of controls and icons. It does not accept numbers, use CSS variables to change individual values:

size="xs"

#
Department
Salary
1AliceJohnsonEngineering95000
2BobSmithMarketing72000
3CarolWilliamsSales68000

size="sm"

#
Department
Salary
1AliceJohnsonEngineering95000
2BobSmithMarketing72000
3CarolWilliamsSales68000

size="md"

#
Department
Salary
1AliceJohnsonEngineering95000
2BobSmithMarketing72000
3CarolWilliamsSales68000

size="lg"

#
Department
Salary
1AliceJohnsonEngineering95000
2BobSmithMarketing72000
3CarolWilliamsSales68000

size="xl"

#
Department
Salary
1AliceJohnsonEngineering95000
2BobSmithMarketing72000
3CarolWilliamsSales68000
import { MantineSize, Stack, Text } from '@mantine/core';
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

const gridSizes: MantineSize[] = ['xs', 'sm', 'md', 'lg', 'xl'];

function SizedGrid({ size }: { size: MantineSize }) {
  const store = useDataGrid({
    data: employees,
    columns: [
      { accessorKey: 'firstName', header: 'First Name', enableSorting: true },
      { accessorKey: 'lastName', header: 'Last Name', enableSorting: true },
      { accessorKey: 'department', header: 'Department' },
      { accessorKey: 'salary', header: 'Salary', meta: { align: 'end' } },
    ],
    getRowId: (row) => row.id,
    size,
    withRowSelection: true,
    withRowNumbers: true,
    withGlobalFilter: true,
    pageSize: 3,
  });

  return (
    <div>
      <Text size="sm" fw={500} mb="xs">
        size="{size}"
      </Text>
      <DataGrid store={store}>
        <DataGrid.Toolbar />
        <DataGrid.Footer />
      </DataGrid>
    </div>
  );
}

function Demo() {
  return (
    <Stack gap="lg">
      {gridSizes.map((size) => (
        <SizedGrid key={size} size={size} />
      ))}
    </Stack>
  );
}

Pass store.getControlSize() to your own buttons and inputs inside the grid so they match the grid size. To let users change the density, call store.setSize:

18 rows
#
First Name
Last Name
Department
Salary
1AliceJohnsonEngineering95000
2BobSmithMarketing72000
3CarolWilliamsSales68000
4DavidBrownHR65000
5EvaDavisFinance88000
6FrankMillerEngineering102000
import { MantineSize, SegmentedControl } from '@mantine/core';
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const store = useDataGrid({
    data: employees,
    columns: [
      { accessorKey: 'firstName', header: 'First Name' },
      { accessorKey: 'lastName', header: 'Last Name' },
      { accessorKey: 'department', header: 'Department' },
      { accessorKey: 'salary', header: 'Salary', meta: { align: 'end' } },
    ],
    getRowId: (row) => row.id,
    withRowSelection: true,
    withRowNumbers: true,
    pageSize: 6,
  });

  return (
    <DataGrid store={store}>
      <DataGrid.Toolbar>
        <DataGrid.RowCount />
        <SegmentedControl
          ml="auto"
          size="xs"
          data={['xs', 'sm', 'md', 'lg', 'xl']}
          value={store.getSize()}
          onChange={(value) => store.setSize(value as MantineSize)}
        />
      </DataGrid.Toolbar>
      <DataGrid.Footer />
    </DataGrid>
  );
}

CSS variables

The following CSS variables are set on the root element. Override them with vars, the Styles API or in a stylesheet.

VariableDescription
--dg-font-sizeFont size of cell content
--dg-row-heightRow height
--dg-header-heightHeader row height
--dg-cell-padding-xHorizontal cell padding
--dg-cell-padding-yVertical cell padding
--dg-control-sizeCheckbox and radio size in utility columns
--dg-icon-sizeChevron, grip, kebab and unsorted arrow size
--dg-footer-heightHeight of DataGrid.Footer
--dg-radiusFrame border-radius
--dg-border-colorFrame, header, toolbar and footer border color
--dg-row-border-colorBorder color between rows
--dg-striped-colorStriped, tinted group and tinted expanded row background
--dg-hover-colorRow, header, group row and toggle hover background
--dg-selected-colorSelected row background
--dg-dirty-colorBackground of cells with dirty status
--dg-invalid-colorBackground of invalid cells and cells with invalid status

Styles API

DataGrid supports classNames and styles props. Selectors are listed in the Styles API table on the DataGrid page. Row and cell states are available as data attributes, for example data-selected, data-striped and data-pinned:

First Name
Last Name
Department
Salary
Status
AliceJohnsonEngineering95000active
BobSmithMarketing72000active
CarolWilliamsSales68000active
DavidBrownHR65000inactive
EvaDavisFinance88000active
FrankMillerEngineering102000active
GraceWilsonMarketing76000active
HenryTaylorSales71000inactive
IreneAndersonEngineering97000active
JamesThomasFinance91000active
KarenJacksonHR63000active
LeoWhiteEngineering110000active
MiaHarrisSales74000active
NathanMartinMarketing69000inactive
OliviaGarciaFinance85000active
PatrickMartinezEngineering99000active
QuinnRobinsonHR67000active
RachelClarkSales73000active
import { DataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  return (
    <DataGrid
      data={employees}
      columns={[
        { accessorKey: 'firstName', header: 'First Name' },
        { accessorKey: 'lastName', header: 'Last Name' },
        { accessorKey: 'department', header: 'Department' },
        { accessorKey: 'salary', header: 'Salary' },
        { accessorKey: 'status', header: 'Status' },
      ]}
      styles={{
        thead: { backgroundColor: 'var(--mantine-color-blue-light)' },
        th: { fontWeight: 700 },
        td: { fontSize: 'var(--mantine-font-size-sm)' },
        tr: { borderBottom: '1px solid var(--mantine-color-border)' },
      }}
    />
  );
}

Compound components

Use compound components to add a toolbar, a selection bar and a footer to the grid. The toolbar and the selection bar are displayed above the table, other children below it:

  • DataGrid.Toolbar -- bar above the table
  • DataGrid.GlobalFilter -- global search input
  • DataGrid.ColumnVisibilityToggle -- column visibility menu button
  • DataGrid.ExportButton -- export menu
  • DataGrid.RowCount -- total / filtered row count text
  • DataGrid.SelectionBar -- bulk actions bar displayed while rows are selected
  • DataGrid.Footer -- bar below the table with status text, page size select and pagination
  • DataGrid.ColumnMenu -- column menu button for custom header cells
First Name
Last Name
Email
Department
Salary
Status
AliceJohnsonalice.johnson@example.comEngineering95000active
BobSmithbob.smith@example.comMarketing72000active
CarolWilliamscarol.williams@example.comSales68000active
DavidBrowndavid.brown@example.comHR65000inactive
EvaDaviseva.davis@example.comFinance88000active
FrankMillerfrank.miller@example.comEngineering102000active
GraceWilsongrace.wilson@example.comMarketing76000active
HenryTaylorhenry.taylor@example.comSales71000inactive
IreneAndersonirene.anderson@example.comEngineering97000active
JamesThomasjames.thomas@example.comFinance91000active
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const store = useDataGrid({
    data: employees,
    columns: [
      { accessorKey: 'firstName', header: 'First Name' },
      { accessorKey: 'lastName', header: 'Last Name' },
      { accessorKey: 'email', header: 'Email', size: 220 },
      { accessorKey: 'department', header: 'Department' },
      { accessorKey: 'salary', header: 'Salary' },
      { accessorKey: 'status', header: 'Status' },
    ],
    withGlobalFilter: true,
    withColumnVisibility: true,
    withRowSelection: true,
    pageSize: 10,
  });

  return (
    <DataGrid store={store}>
      <DataGrid.Toolbar />
      <DataGrid.Footer statusFormat="long" />
    </DataGrid>
  );
}

Toolbar

DataGrid.Toolbar without children renders the global filter, the column visibility toggle and the export button, each when its feature is enabled. Pass children to replace the default content, use a div with flex: 1 as a spacer. DataGrid.RowCount displays the number of rows, for example 5 of 18 rows when the data is filtered:

18 rows
First Name
Last Name
Email
Department
Salary
AliceJohnsonalice.johnson@example.comEngineering95000
BobSmithbob.smith@example.comMarketing72000
CarolWilliamscarol.williams@example.comSales68000
DavidBrowndavid.brown@example.comHR65000
EvaDaviseva.davis@example.comFinance88000
FrankMillerfrank.miller@example.comEngineering102000
GraceWilsongrace.wilson@example.comMarketing76000
HenryTaylorhenry.taylor@example.comSales71000
IreneAndersonirene.anderson@example.comEngineering97000
JamesThomasjames.thomas@example.comFinance91000
import { PlusIcon } from '@phosphor-icons/react';
import { Button } from '@mantine/core';
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const store = useDataGrid({
    data: employees,
    columns: [
      { accessorKey: 'firstName', header: 'First Name' },
      { accessorKey: 'lastName', header: 'Last Name' },
      { accessorKey: 'email', header: 'Email', size: 220 },
      { accessorKey: 'department', header: 'Department' },
      { accessorKey: 'salary', header: 'Salary', meta: { align: 'end' } },
    ],
    withGlobalFilter: true,
    withColumnVisibility: true,
    pageSize: 10,
  });

  return (
    <DataGrid store={store}>
      <DataGrid.Toolbar>
        <DataGrid.GlobalFilter />
        <DataGrid.RowCount />
        <div style={{ flex: 1 }} />
        <Button size={store.getControlSize()} leftSection={<PlusIcon size={14} />}>
          Add employee
        </Button>
        <DataGrid.ColumnVisibilityToggle />
        <DataGrid.ExportButton fileName="employees" formats={['csv', 'excel']} />
      </DataGrid.Toolbar>
      <DataGrid.Footer />
    </DataGrid>
  );
}

Export button

DataGrid.ExportButton opens a menu with CSV, Excel, print and copy to clipboard items:

  • formats – formats to display and their order, a single format renders a button without a menu
  • fileName – name of the downloaded file, data by default
  • rows – rows to export: all (default), filtered, selected or page
  • columns – columns to export: visible (default), all or an array of column ids
  • onExport – called with the format after an export

Utility columns, actions columns and columns with meta.disableExport are never exported:

First Name
Last Name
Email
Department
Salary
AliceJohnsonalice.johnson@example.comEngineering95000
BobSmithbob.smith@example.comMarketing72000
CarolWilliamscarol.williams@example.comSales68000
DavidBrowndavid.brown@example.comHR65000
EvaDaviseva.davis@example.comFinance88000
FrankMillerfrank.miller@example.comEngineering102000
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const store = useDataGrid({
    data: employees,
    columns: [
      { accessorKey: 'firstName', header: 'First Name' },
      { accessorKey: 'lastName', header: 'Last Name' },
      { accessorKey: 'email', header: 'Email', size: 220 },
      { accessorKey: 'department', header: 'Department' },
      { accessorKey: 'salary', header: 'Salary', meta: { align: 'end' } },
    ],
    getRowId: (row) => row.id,
    withRowSelection: true,
    pageSize: 6,
  });

  return (
    <DataGrid store={store}>
      <DataGrid.Toolbar>
        <DataGrid.ExportButton fileName="employees" />
        <DataGrid.ExportButton formats={['csv']} rows="selected" fileName="selected-employees">
          Download selected
        </DataGrid.ExportButton>
        <DataGrid.ExportButton formats={['copy']} rows="page" columns={['firstName', 'lastName']}>
          Copy names
        </DataGrid.ExportButton>
      </DataGrid.Toolbar>
      <DataGrid.Footer />
    </DataGrid>
  );
}

Selection bar

DataGrid.SelectionBar replaces the toolbar while rows are selected. It displays the number of selected rows, bulk actions passed as children and a button that clears the selection. Set withCloseButton={false} to remove the close button:

First Name
Last Name
Department
Status
Salary
AliceJohnsonEngineeringactive95000
BobSmithMarketingactive72000
CarolWilliamsSalesactive68000
DavidBrownHRinactive65000
EvaDavisFinanceactive88000
FrankMillerEngineeringactive102000
GraceWilsonMarketingactive76000
HenryTaylorSalesinactive71000
import { useState } from 'react';
import { RowSelectionState } from '@tanstack/react-table';
import { Button } from '@mantine/core';
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const [data, setData] = useState(employees);
  const [rowSelection, setRowSelection] = useState<RowSelectionState>({});

  const store = useDataGrid({
    data,
    columns: [
      { accessorKey: 'firstName', header: 'First Name' },
      { accessorKey: 'lastName', header: 'Last Name' },
      { accessorKey: 'department', header: 'Department' },
      { accessorKey: 'status', header: 'Status' },
      { accessorKey: 'salary', header: 'Salary', meta: { align: 'end' } },
    ],
    getRowId: (row) => row.id,
    withRowSelection: true,
    withGlobalFilter: true,
    rowSelection,
    onRowSelectionChange: setRowSelection,
    pageSize: 8,
  });

  const selectedIds = () => new Set(Object.keys(rowSelection));

  const deactivateSelected = () => {
    const ids = selectedIds();
    setData((current) =>
      current.map((row) => (ids.has(row.id) ? { ...row, status: 'inactive' as const } : row))
    );
    setRowSelection({});
  };

  const deleteSelected = () => {
    const ids = selectedIds();
    setData((current) => current.filter((row) => !ids.has(row.id)));
    setRowSelection({});
  };

  return (
    <DataGrid store={store}>
      <DataGrid.Toolbar />
      <DataGrid.SelectionBar>
        <Button size={store.getControlSize()} variant="default" onClick={deactivateSelected}>
          Deactivate
        </Button>
        <Button size={store.getControlSize()} variant="default" onClick={deleteSelected}>
          Delete
        </Button>
      </DataGrid.SelectionBar>
      <DataGrid.Footer />
    </DataGrid>
  );
}

Set floating to display the bar over the grid content near the bottom of the grid, the toolbar stays visible:

First Name
Last Name
Department
Status
Salary
AliceJohnsonEngineeringactive95000
BobSmithMarketingactive72000
CarolWilliamsSalesactive68000
DavidBrownHRinactive65000
EvaDavisFinanceactive88000
FrankMillerEngineeringactive102000
GraceWilsonMarketingactive76000
HenryTaylorSalesinactive71000
import { useState } from 'react';
import { RowSelectionState } from '@tanstack/react-table';
import { Button } from '@mantine/core';
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const [data, setData] = useState(employees);
  const [rowSelection, setRowSelection] = useState<RowSelectionState>({});

  const store = useDataGrid({
    data,
    columns: [
      { accessorKey: 'firstName', header: 'First Name' },
      { accessorKey: 'lastName', header: 'Last Name' },
      { accessorKey: 'department', header: 'Department' },
      { accessorKey: 'status', header: 'Status' },
      { accessorKey: 'salary', header: 'Salary', meta: { align: 'end' } },
    ],
    getRowId: (row) => row.id,
    withRowSelection: true,
    withGlobalFilter: true,
    rowSelection,
    onRowSelectionChange: setRowSelection,
    pageSize: 8,
  });

  const selectedIds = () => new Set(Object.keys(rowSelection));

  const deactivateSelected = () => {
    const ids = selectedIds();
    setData((current) =>
      current.map((row) => (ids.has(row.id) ? { ...row, status: 'inactive' as const } : row))
    );
    setRowSelection({});
  };

  const deleteSelected = () => {
    const ids = selectedIds();
    setData((current) => current.filter((row) => !ids.has(row.id)));
    setRowSelection({});
  };

  return (
    <DataGrid store={store}>
      <DataGrid.Toolbar />
      <DataGrid.SelectionBar floating>
        <Button size={store.getControlSize()} variant="default" onClick={deactivateSelected}>
          Deactivate
        </Button>
        <Button size={store.getControlSize()} variant="default" onClick={deleteSelected}>
          Delete
        </Button>
      </DataGrid.SelectionBar>
      <DataGrid.Footer />
    </DataGrid>
  );
}

Footer

DataGrid.Footer renders the status text, the page size select and pagination controls in one bar at the bottom of the frame, see Pagination.

Column menu

Set withColumnMenu on DataGrid to add a menu button to every data column header. Menu items depend on the features enabled for the column: sorting, reordering, pinning, hiding, grouping and resizing. Use columnMenuItems to add your own items and meta.disableColumnMenu to hide the menu of one column:

Email
AliceJohnsonalice.johnson@example.comEngineering95000
BobSmithbob.smith@example.comMarketing72000
CarolWilliamscarol.williams@example.comSales68000
DavidBrowndavid.brown@example.comHR65000
EvaDaviseva.davis@example.comFinance88000
FrankMillerfrank.miller@example.comEngineering102000
GraceWilsongrace.wilson@example.comMarketing76000
HenryTaylorhenry.taylor@example.comSales71000
IreneAndersonirene.anderson@example.comEngineering97000
JamesThomasjames.thomas@example.comFinance91000
KarenJacksonkaren.jackson@example.comHR63000
LeoWhiteleo.white@example.comEngineering110000
MiaHarrismia.harris@example.comSales74000
NathanMartinnathan.martin@example.comMarketing69000
OliviaGarciaolivia.garcia@example.comFinance85000
PatrickMartinezpatrick.martinez@example.comEngineering99000
QuinnRobinsonquinn.robinson@example.comHR67000
RachelClarkrachel.clark@example.comSales73000
import { Menu } from '@mantine/core';
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const store = useDataGrid({
    data: employees,
    columns: [
      { accessorKey: 'firstName', header: 'First Name', enableSorting: true },
      { accessorKey: 'lastName', header: 'Last Name', enableSorting: true },
      {
        accessorKey: 'email',
        header: 'Email',
        size: 220,
        meta: { disableColumnMenu: true },
      },
      { accessorKey: 'department', header: 'Department', enableSorting: true },
      { accessorKey: 'salary', header: 'Salary', enableSorting: true, meta: { align: 'end' } },
    ],
    withColumnVisibility: true,
    withColumnPinning: true,
    withColumnResizing: true,
    withColumnReorder: true,
    withGrouping: true,
  });

  return (
    <DataGrid
      store={store}
      withColumnMenu
      columnMenuItems={(column) => (
        <Menu.Item onClick={() => navigator.clipboard.writeText(column.id)}>Copy column id</Menu.Item>
      )}
    />
  );
}

To render the column menu inside your own header cell, use DataGrid.ColumnMenu and pass the column instance to it. children are added after the built-in items:

{
  accessorKey: 'name',
  header: ({ column }) => (
    <Group justify="space-between" wrap="nowrap">
      Name
      <DataGrid.ColumnMenu column={column}>
        <Menu.Item>Custom item</Menu.Item>
      </DataGrid.ColumnMenu>
    </Group>
  ),
}

Column meta

meta of a column definition contains settings specific to the grid:

interface DataGridColumnMeta<TData extends RowData = any, TValue = unknown> {
  /** Label for menus, list view, group rows and exports. Falls back to a string header, then the column id. */
  label?: string;

  /** Alignment of header, body and footer cells. */
  align?: 'start' | 'center' | 'end';

  /** Marks a display column containing row action buttons. */
  type?: 'actions';

  /** Set by the grid on its utility columns. */
  utility?: DataGridUtilityColumn;

  /** Hide the column menu for this column. */
  disableColumnMenu?: boolean;

  /** Exclude the column from cell and row editing. */
  disableEditing?: boolean;

  /** Exclude the column from all exports. */
  disableExport?: boolean;

  /** Label above the aggregated value in the totals row. */
  aggregationLabel?: string;
  formatAggregatedValue?: (value: unknown, rows: DataGridRow<TData>[]) => ReactNode;

  /** Render a custom editor for this column. */
  editComponent?: (props: DataGridEditComponentProps<TData, TValue>) => ReactNode;

  /** Return an error message to prevent saving. */
  validate?: (value: unknown, row: DataGridRow<TData>) => ReactNode | null | undefined;
}

See Editing for examples of action columns, custom editors and validation.

Labels

Use the labels prop of DataGrid to change or translate text labels. All keys are optional, {token} placeholders are replaced with values:

<DataGrid
  store={store}
  labels={{
    globalFilterPlaceholder: 'Rechercher...',
    columnVisibilityLabel: 'Colonnes',
    rowNumber: 'N°',
    selectAll: 'Tout sélectionner',
    selectRow: 'Sélectionner la ligne',
    expandRow: 'Développer',
    collapseRow: 'Réduire',
    exportLabel: 'Exporter',
    exportCsv: 'CSV',
    exportExcel: 'Excel',
    exportPrint: 'Imprimer',
    exportCopy: 'Copier',
    rowCount: '{count} lignes',
    rowCountOne: '{count} ligne',
    rowCountFiltered: '{filtered} sur {count} lignes',
    selectionBarSelected: '{count} sélectionnées',
    selectionBarClear: 'Effacer la sélection',
    pageSize: '{count} par page',
    pageSizeLabel: 'Lignes par page',
    footerRange: '{from}–{to} sur {total}',
    footerRangeLong: 'Affichage de {from}–{to} sur {total}',
    footerRows: '{count} lignes',
    footerRowsOne: '{count} ligne',
    footerSelected: '{count} sélectionnées',
    footerPage: 'Page {page} sur {total}',
    footerPageUnknownTotal: 'Page {page}',
    paginationPrevious: 'Page précédente',
    paginationNext: 'Page suivante',
    aggregationSum: 'Somme',
    aggregationMean: 'Moyenne',
    saveRow: 'Enregistrer',
    cancelRow: 'Annuler',
    columnMenu: 'Menu de la colonne',
    columnMenuSortAsc: 'Tri croissant',
    columnMenuMoveLeft: 'Déplacer à gauche',
  }}
/>

The full list of keys is the DataGridLabels type, exported from the package together with DEFAULT_LABELS.

State persistence

To save and restore grid state, use controlled state options of useDataGrid. The example below saves the sorting state to localStorage:

import { useState, useEffect } from 'react';
import { SortingState } from '@tanstack/react-table';
import { DataGrid, useDataGrid } from '@mantine/data-grid';

const STORAGE_KEY = 'my-grid-state';

function Demo() {
  const [sorting, setSorting] = useState<SortingState>(() => {
    const saved = localStorage.getItem(STORAGE_KEY);
    return saved ? JSON.parse(saved).sorting : [];
  });

  useEffect(() => {
    localStorage.setItem(STORAGE_KEY, JSON.stringify({ sorting }));
  }, [sorting]);

  const store = useDataGrid({
    data,
    columns,
    sorting,
    onSortingChange: setSorting,
  });

  return <DataGrid store={store} />;
}

useDataGridState

useDataGridState saves the state keys listed in persistedState to localStorage and restores them on mount:

import { DataGrid, useDataGrid, useDataGridState } from '@mantine/data-grid';

function Demo() {
  const store = useDataGrid({ data, columns, withSorting: true, withColumnReorder: true });

  useDataGridState({
    store,
    stateStorageKey: 'my-grid-state',
    persistedState: ['sorting', 'columnOrder', 'columnVisibility', 'size'],
  });

  return <DataGrid store={store} />;
}

Theme integration

Use DataGrid.extend to set default props and class names for all grids in your application:

import { createTheme } from '@mantine/core';
import { DataGrid } from '@mantine/data-grid';

const theme = createTheme({
  components: {
    DataGrid: DataGrid.extend({
      defaultProps: { withRowBorders: 'subtle', highlightOnHover: true, radius: 'md' },
      classNames: { root: 'my-grid-root' },
    }),
  },
});

Dark mode

DataGrid colors are based on Mantine CSS variables and follow the current color scheme, no additional configuration is required.

ScrollArea configuration

The table is wrapped in ScrollArea. Use scrollAreaProps to pass props to it, or set withScrollArea={false} to use native scrollbars. For virtualized grids, set withScrollArea to enable ScrollArea. This option does not apply to list view.

<DataGrid
  store={store}
  scrollAreaProps={{ type: 'always', offsetScrollbars: true }}
/>

TanStack passthrough

Use tableOptions in useDataGrid to pass options that the hook does not cover to TanStack Table:

const store = useDataGrid({
  data,
  columns,
  tableOptions: {
    enableMultiSort: true,
    maxMultiSortColCount: 3,
    sortDescFirst: false,
    debugTable: process.env.NODE_ENV === 'development',
  },
});