Pinning

DataGrid column and row pinning

Column pinning

Pass columnPinning to useDataGrid with start and end arrays of column ids to keep columns visible while scrolling horizontally. Utility columns (selection, expand, row numbers, reorder) are always pinned first and cannot be unpinned:

First Name
Last Name
Email
Department
Salary
Start Date
Status
AliceJohnsonalice.johnson@example.comEngineering950002021-03-15active
BobSmithbob.smith@example.comMarketing720002020-07-01active
CarolWilliamscarol.williams@example.comSales680002022-01-10active
DavidBrowndavid.brown@example.comHR650002019-11-20inactive
EvaDaviseva.davis@example.comFinance880002021-06-05active
FrankMillerfrank.miller@example.comEngineering1020002018-09-12active
GraceWilsongrace.wilson@example.comMarketing760002022-04-18active
HenryTaylorhenry.taylor@example.comSales710002020-02-28inactive
IreneAndersonirene.anderson@example.comEngineering970002021-08-30active
JamesThomasjames.thomas@example.comFinance910002019-05-14active
KarenJacksonkaren.jackson@example.comHR630002023-01-09active
LeoWhiteleo.white@example.comEngineering1100002017-12-01active
MiaHarrismia.harris@example.comSales740002022-07-22active
NathanMartinnathan.martin@example.comMarketing690002021-10-03inactive
OliviaGarciaolivia.garcia@example.comFinance850002020-04-11active
PatrickMartinezpatrick.martinez@example.comEngineering990002019-08-25active
QuinnRobinsonquinn.robinson@example.comHR670002022-11-14active
RachelClarkrachel.clark@example.comSales730002021-02-07active
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const store = useDataGrid({
    data: employees,
    columns: [
      { accessorKey: 'firstName', header: 'First Name', size: 150 },
      { accessorKey: 'lastName', header: 'Last Name', size: 150 },
      { accessorKey: 'email', header: 'Email', size: 250 },
      { accessorKey: 'department', header: 'Department', size: 150 },
      { accessorKey: 'salary', header: 'Salary', size: 120 },
      { accessorKey: 'startDate', header: 'Start Date', size: 150 },
      { accessorKey: 'status', header: 'Status', size: 120 },
    ],
    columnPinning: { start: ['firstName'], end: [] },
  });

  return (
    <div style={{ maxWidth: 600 }}>
      <DataGrid store={store} />
    </div>
  );
}

Pin multiple columns

Several columns can be pinned to each edge:

First Name
Last Name
Email
Department
Salary
Start Date
Status
AliceJohnsonalice.johnson@example.comEngineering950002021-03-15active
BobSmithbob.smith@example.comMarketing720002020-07-01active
CarolWilliamscarol.williams@example.comSales680002022-01-10active
DavidBrowndavid.brown@example.comHR650002019-11-20inactive
EvaDaviseva.davis@example.comFinance880002021-06-05active
FrankMillerfrank.miller@example.comEngineering1020002018-09-12active
GraceWilsongrace.wilson@example.comMarketing760002022-04-18active
HenryTaylorhenry.taylor@example.comSales710002020-02-28inactive
IreneAndersonirene.anderson@example.comEngineering970002021-08-30active
JamesThomasjames.thomas@example.comFinance910002019-05-14active
KarenJacksonkaren.jackson@example.comHR630002023-01-09active
LeoWhiteleo.white@example.comEngineering1100002017-12-01active
MiaHarrismia.harris@example.comSales740002022-07-22active
NathanMartinnathan.martin@example.comMarketing690002021-10-03inactive
OliviaGarciaolivia.garcia@example.comFinance850002020-04-11active
PatrickMartinezpatrick.martinez@example.comEngineering990002019-08-25active
QuinnRobinsonquinn.robinson@example.comHR670002022-11-14active
RachelClarkrachel.clark@example.comSales730002021-02-07active
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const store = useDataGrid({
    data: employees,
    columns: [
      { accessorKey: 'firstName', header: 'First Name', size: 150 },
      { accessorKey: 'lastName', header: 'Last Name', size: 150 },
      { accessorKey: 'email', header: 'Email', size: 250 },
      { accessorKey: 'department', header: 'Department', size: 150 },
      { accessorKey: 'salary', header: 'Salary', size: 150 },
      { accessorKey: 'startDate', header: 'Start Date', size: 150 },
      { accessorKey: 'status', header: 'Status', size: 120 },
    ],
    columnPinning: { start: ['firstName', 'lastName'], end: ['status'] },
  });

  return (
    <div style={{ maxWidth: 600 }}>
      <DataGrid store={store} />
    </div>
  );
}

Interactive column pinning

Use controlled columnPinning and onColumnPinningChange to let users pin and unpin columns. With withColumnMenu on DataGrid, every column gets Pin to left, Pin to right and Unpin items in its header menu:

Pinned start: [], end: []

First Name
Last Name
Email
Department
Salary
Start Date
Status
AliceJohnsonalice.johnson@example.comEngineering950002021-03-15active
BobSmithbob.smith@example.comMarketing720002020-07-01active
CarolWilliamscarol.williams@example.comSales680002022-01-10active
DavidBrowndavid.brown@example.comHR650002019-11-20inactive
EvaDaviseva.davis@example.comFinance880002021-06-05active
FrankMillerfrank.miller@example.comEngineering1020002018-09-12active
GraceWilsongrace.wilson@example.comMarketing760002022-04-18active
HenryTaylorhenry.taylor@example.comSales710002020-02-28inactive
IreneAndersonirene.anderson@example.comEngineering970002021-08-30active
JamesThomasjames.thomas@example.comFinance910002019-05-14active
KarenJacksonkaren.jackson@example.comHR630002023-01-09active
LeoWhiteleo.white@example.comEngineering1100002017-12-01active
MiaHarrismia.harris@example.comSales740002022-07-22active
NathanMartinnathan.martin@example.comMarketing690002021-10-03inactive
OliviaGarciaolivia.garcia@example.comFinance850002020-04-11active
PatrickMartinezpatrick.martinez@example.comEngineering990002019-08-25active
QuinnRobinsonquinn.robinson@example.comHR670002022-11-14active
RachelClarkrachel.clark@example.comSales730002021-02-07active
import { useState } from 'react';
import { ColumnPinningState } from '@tanstack/react-table';
import { Button, Code, Group, Text } from '@mantine/core';
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const [columnPinning, setColumnPinning] = useState<ColumnPinningState>({
    start: [],
    end: [],
  });

  const store = useDataGrid({
    data: employees,
    columns: [
      { accessorKey: 'firstName', header: 'First Name', size: 150 },
      { accessorKey: 'lastName', header: 'Last Name', size: 150 },
      { accessorKey: 'email', header: 'Email', size: 250 },
      { accessorKey: 'department', header: 'Department', size: 150 },
      { accessorKey: 'salary', header: 'Salary', size: 150 },
      { accessorKey: 'startDate', header: 'Start Date', size: 150 },
      { accessorKey: 'status', header: 'Status', size: 120 },
    ],
    columnPinning,
    onColumnPinningChange: setColumnPinning,
  });

  return (
    <div style={{ maxWidth: 600 }}>
      <Text mb="xs">
        Pinned start: <Code>{JSON.stringify(columnPinning.start)}</Code>, end:{' '}
        <Code>{JSON.stringify(columnPinning.end)}</Code>
      </Text>
      <Group mb="md">
        <Button size="xs" onClick={() => setColumnPinning({ start: ['firstName'], end: [] })}>
          Pin firstName to start
        </Button>
        <Button size="xs" onClick={() => setColumnPinning({ start: [], end: ['status'] })}>
          Pin status to end
        </Button>
        <Button
          size="xs"
          onClick={() => setColumnPinning({ start: ['firstName'], end: ['status'] })}
        >
          Pin both
        </Button>
        <Button
          size="xs"
          variant="default"
          onClick={() => setColumnPinning({ start: [], end: [] })}
        >
          Unpin all
        </Button>
      </Group>
      <DataGrid store={store} />
    </div>
  );
}

Row pinning

Pass rowPinning to useDataGrid with top and bottom arrays of row ids to keep rows visible while scrolling vertically. getRowId is required:

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, 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' },
      { accessorKey: 'status', header: 'Status' },
    ],
    rowPinning: { top: ['1'], bottom: [] },
    getRowId: (row) => row.id,
  });

  return <DataGrid store={store} stickyHeader height={300} />;
}

Interactive row pinning

Call row.pin('top'), row.pin('bottom') or row.pin(false) from a custom cell to let users pin and unpin rows:

Pin
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 { useState } from 'react';
import { RowPinningState } from '@tanstack/react-table';
import { ActionIcon, Group } from '@mantine/core';
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const [rowPinning, setRowPinning] = useState<RowPinningState>({
    top: [],
    bottom: [],
  });

  const store = useDataGrid({
    data: employees,
    columns: [
      {
        id: 'pin',
        header: 'Pin',
        size: 100,
        cell: ({ row }) => (
          <Group gap={4} wrap="nowrap">
            <ActionIcon
              size="xs"
              variant={row.getIsPinned() === 'top' ? 'filled' : 'default'}
              onClick={() => row.pin(row.getIsPinned() === 'top' ? false : 'top')}
            >
              &#x2191;
            </ActionIcon>
            <ActionIcon
              size="xs"
              variant={row.getIsPinned() === 'bottom' ? 'filled' : 'default'}
              onClick={() => row.pin(row.getIsPinned() === 'bottom' ? false : 'bottom')}
            >
              &#x2193;
            </ActionIcon>
          </Group>
        ),
      },
      { accessorKey: 'firstName', header: 'First Name' },
      { accessorKey: 'lastName', header: 'Last Name' },
      { accessorKey: 'department', header: 'Department' },
      { accessorKey: 'salary', header: 'Salary' },
      { accessorKey: 'status', header: 'Status' },
    ],
    rowPinning,
    onRowPinningChange: setRowPinning,
    enableRowPinning: true,
    keepPinnedRows: true,
    getRowId: (row) => row.id,
  });

  return <DataGrid store={store} stickyHeader height={300} />;
}

Combined row and column pinning

Row pinning and column pinning can be used together:

First Name
Last Name
Email
Department
Salary
Start Date
Status
AliceJohnsonalice.johnson@example.comEngineering950002021-03-15active
BobSmithbob.smith@example.comMarketing720002020-07-01active
CarolWilliamscarol.williams@example.comSales680002022-01-10active
DavidBrowndavid.brown@example.comHR650002019-11-20inactive
EvaDaviseva.davis@example.comFinance880002021-06-05active
FrankMillerfrank.miller@example.comEngineering1020002018-09-12active
GraceWilsongrace.wilson@example.comMarketing760002022-04-18active
HenryTaylorhenry.taylor@example.comSales710002020-02-28inactive
IreneAndersonirene.anderson@example.comEngineering970002021-08-30active
JamesThomasjames.thomas@example.comFinance910002019-05-14active
KarenJacksonkaren.jackson@example.comHR630002023-01-09active
LeoWhiteleo.white@example.comEngineering1100002017-12-01active
MiaHarrismia.harris@example.comSales740002022-07-22active
NathanMartinnathan.martin@example.comMarketing690002021-10-03inactive
OliviaGarciaolivia.garcia@example.comFinance850002020-04-11active
PatrickMartinezpatrick.martinez@example.comEngineering990002019-08-25active
QuinnRobinsonquinn.robinson@example.comHR670002022-11-14active
RachelClarkrachel.clark@example.comSales730002021-02-07active
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const store = useDataGrid({
    data: employees,
    columns: [
      { accessorKey: 'firstName', header: 'First Name', size: 150 },
      { accessorKey: 'lastName', header: 'Last Name', size: 150 },
      { accessorKey: 'email', header: 'Email', size: 250 },
      { accessorKey: 'department', header: 'Department', size: 150 },
      { accessorKey: 'salary', header: 'Salary', size: 150 },
      { accessorKey: 'startDate', header: 'Start Date', size: 150 },
      { accessorKey: 'status', header: 'Status', size: 120 },
    ],
    columnPinning: { start: ['firstName'], end: [] },
    rowPinning: { top: ['1'], bottom: [] },
    getRowId: (row) => row.id,
  });

  return (
    <div style={{ maxWidth: 600 }}>
      <DataGrid store={store} stickyHeader height={300} />
    </div>
  );
}

Pinning with header groups

Column pinning works with grouped headers. A group header is pinned when all of its columns are pinned to the same side:

Name
Details
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
KarenJacksonkaren.jackson@example.comHR63000active
LeoWhiteleo.white@example.comEngineering110000active
MiaHarrismia.harris@example.comSales74000active
NathanMartinnathan.martin@example.comMarketing69000inactive
OliviaGarciaolivia.garcia@example.comFinance85000active
PatrickMartinezpatrick.martinez@example.comEngineering99000active
QuinnRobinsonquinn.robinson@example.comHR67000active
RachelClarkrachel.clark@example.comSales73000active
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const store = useDataGrid({
    data: employees,
    columns: [
      {
        header: 'Name',
        columns: [
          { accessorKey: 'firstName', header: 'First Name', size: 150 },
          { accessorKey: 'lastName', header: 'Last Name', size: 150 },
        ],
      },
      {
        header: 'Details',
        columns: [
          { accessorKey: 'email', header: 'Email', size: 250 },
          { accessorKey: 'department', header: 'Department', size: 150 },
        ],
      },
      { accessorKey: 'salary', header: 'Salary', size: 120 },
      { accessorKey: 'status', header: 'Status', size: 120 },
    ],
    columnPinning: { start: ['firstName', 'lastName'], end: [] },
  });

  return (
    <div style={{ maxWidth: 600 }}>
      <DataGrid store={store} />
    </div>
  );
}

Sticky header

Set stickyHeader on DataGrid to keep the header visible while the page scrolls. Use stickyHeaderOffset to set where the header sticks, for example under a fixed app header:

<DataGrid store={store} stickyHeader stickyHeaderOffset={60} />

Top-pinned rows stick under the sticky header. With virtualize, the header is always sticky and stickyHeaderOffset is not applied.

keepPinnedRows

By default, pinned rows stay visible when filters or pagination would hide them. Set keepPinnedRows: false in useDataGrid to let them be hidden:

const store = useDataGrid({
  data,
  columns,
  rowPinning: { top: ['1'], bottom: [] },
  keepPinnedRows: false,
  getRowId: (row) => row.id,
});

Per-row pinning control

Pass a function to enableRowPinning to control which rows can be pinned:

const store = useDataGrid({
  data,
  columns,
  rowPinning: { top: [], bottom: [] },
  enableRowPinning: (row) => row.original.status === 'active',
  getRowId: (row) => row.id,
});

Controlled pinning state

Column pinning is controlled with columnPinning and onColumnPinningChange, row pinning with rowPinning and onRowPinningChange. Read the current state from the store:

const store = useDataGrid({ data, columns, columnPinning, onColumnPinningChange });

// Read current state
store.getColumnPinning() // { start: ['firstName'], end: [] }
store.getRowPinning()    // { top: ['1'], bottom: [] }

Sticky positioning design

Pinned cells use position: sticky and inherit the background of their row, so stripes, hover and selection styles apply to them.

Limitations

  • Rows of a grid with pinned columns have an opaque --mantine-color-body background. If the grid is rendered on a tinted surface, override the row background with Styles API.
  • Row pinning is not supported with virtualize. Column pinning works with both standard and virtualized grids.