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 |
|---|---|---|---|---|---|---|
| Alice | Johnson | alice.johnson@example.com | Engineering | 95000 | 2021-03-15 | active |
| Bob | Smith | bob.smith@example.com | Marketing | 72000 | 2020-07-01 | active |
| Carol | Williams | carol.williams@example.com | Sales | 68000 | 2022-01-10 | active |
| David | Brown | david.brown@example.com | HR | 65000 | 2019-11-20 | inactive |
| Eva | Davis | eva.davis@example.com | Finance | 88000 | 2021-06-05 | active |
| Frank | Miller | frank.miller@example.com | Engineering | 102000 | 2018-09-12 | active |
| Grace | Wilson | grace.wilson@example.com | Marketing | 76000 | 2022-04-18 | active |
| Henry | Taylor | henry.taylor@example.com | Sales | 71000 | 2020-02-28 | inactive |
| Irene | Anderson | irene.anderson@example.com | Engineering | 97000 | 2021-08-30 | active |
| James | Thomas | james.thomas@example.com | Finance | 91000 | 2019-05-14 | active |
| Karen | Jackson | karen.jackson@example.com | HR | 63000 | 2023-01-09 | active |
| Leo | White | leo.white@example.com | Engineering | 110000 | 2017-12-01 | active |
| Mia | Harris | mia.harris@example.com | Sales | 74000 | 2022-07-22 | active |
| Nathan | Martin | nathan.martin@example.com | Marketing | 69000 | 2021-10-03 | inactive |
| Olivia | Garcia | olivia.garcia@example.com | Finance | 85000 | 2020-04-11 | active |
| Patrick | Martinez | patrick.martinez@example.com | Engineering | 99000 | 2019-08-25 | active |
| Quinn | Robinson | quinn.robinson@example.com | HR | 67000 | 2022-11-14 | active |
| Rachel | Clark | rachel.clark@example.com | Sales | 73000 | 2021-02-07 | active |
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 |
|---|---|---|---|---|---|---|
| Alice | Johnson | alice.johnson@example.com | Engineering | 95000 | 2021-03-15 | active |
| Bob | Smith | bob.smith@example.com | Marketing | 72000 | 2020-07-01 | active |
| Carol | Williams | carol.williams@example.com | Sales | 68000 | 2022-01-10 | active |
| David | Brown | david.brown@example.com | HR | 65000 | 2019-11-20 | inactive |
| Eva | Davis | eva.davis@example.com | Finance | 88000 | 2021-06-05 | active |
| Frank | Miller | frank.miller@example.com | Engineering | 102000 | 2018-09-12 | active |
| Grace | Wilson | grace.wilson@example.com | Marketing | 76000 | 2022-04-18 | active |
| Henry | Taylor | henry.taylor@example.com | Sales | 71000 | 2020-02-28 | inactive |
| Irene | Anderson | irene.anderson@example.com | Engineering | 97000 | 2021-08-30 | active |
| James | Thomas | james.thomas@example.com | Finance | 91000 | 2019-05-14 | active |
| Karen | Jackson | karen.jackson@example.com | HR | 63000 | 2023-01-09 | active |
| Leo | White | leo.white@example.com | Engineering | 110000 | 2017-12-01 | active |
| Mia | Harris | mia.harris@example.com | Sales | 74000 | 2022-07-22 | active |
| Nathan | Martin | nathan.martin@example.com | Marketing | 69000 | 2021-10-03 | inactive |
| Olivia | Garcia | olivia.garcia@example.com | Finance | 85000 | 2020-04-11 | active |
| Patrick | Martinez | patrick.martinez@example.com | Engineering | 99000 | 2019-08-25 | active |
| Quinn | Robinson | quinn.robinson@example.com | HR | 67000 | 2022-11-14 | active |
| Rachel | Clark | rachel.clark@example.com | Sales | 73000 | 2021-02-07 | active |
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 |
|---|---|---|---|---|---|---|
| Alice | Johnson | alice.johnson@example.com | Engineering | 95000 | 2021-03-15 | active |
| Bob | Smith | bob.smith@example.com | Marketing | 72000 | 2020-07-01 | active |
| Carol | Williams | carol.williams@example.com | Sales | 68000 | 2022-01-10 | active |
| David | Brown | david.brown@example.com | HR | 65000 | 2019-11-20 | inactive |
| Eva | Davis | eva.davis@example.com | Finance | 88000 | 2021-06-05 | active |
| Frank | Miller | frank.miller@example.com | Engineering | 102000 | 2018-09-12 | active |
| Grace | Wilson | grace.wilson@example.com | Marketing | 76000 | 2022-04-18 | active |
| Henry | Taylor | henry.taylor@example.com | Sales | 71000 | 2020-02-28 | inactive |
| Irene | Anderson | irene.anderson@example.com | Engineering | 97000 | 2021-08-30 | active |
| James | Thomas | james.thomas@example.com | Finance | 91000 | 2019-05-14 | active |
| Karen | Jackson | karen.jackson@example.com | HR | 63000 | 2023-01-09 | active |
| Leo | White | leo.white@example.com | Engineering | 110000 | 2017-12-01 | active |
| Mia | Harris | mia.harris@example.com | Sales | 74000 | 2022-07-22 | active |
| Nathan | Martin | nathan.martin@example.com | Marketing | 69000 | 2021-10-03 | inactive |
| Olivia | Garcia | olivia.garcia@example.com | Finance | 85000 | 2020-04-11 | active |
| Patrick | Martinez | patrick.martinez@example.com | Engineering | 99000 | 2019-08-25 | active |
| Quinn | Robinson | quinn.robinson@example.com | HR | 67000 | 2022-11-14 | active |
| Rachel | Clark | rachel.clark@example.com | Sales | 73000 | 2021-02-07 | active |
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 |
|---|---|---|---|---|
| Alice | Johnson | Engineering | 95000 | active |
| Bob | Smith | Marketing | 72000 | active |
| Carol | Williams | Sales | 68000 | active |
| David | Brown | HR | 65000 | inactive |
| Eva | Davis | Finance | 88000 | active |
| Frank | Miller | Engineering | 102000 | active |
| Grace | Wilson | Marketing | 76000 | active |
| Henry | Taylor | Sales | 71000 | inactive |
| Irene | Anderson | Engineering | 97000 | active |
| James | Thomas | Finance | 91000 | active |
| Karen | Jackson | HR | 63000 | active |
| Leo | White | Engineering | 110000 | active |
| Mia | Harris | Sales | 74000 | active |
| Nathan | Martin | Marketing | 69000 | inactive |
| Olivia | Garcia | Finance | 85000 | active |
| Patrick | Martinez | Engineering | 99000 | active |
| Quinn | Robinson | HR | 67000 | active |
| Rachel | Clark | Sales | 73000 | active |
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 |
|---|---|---|---|---|---|
| Alice | Johnson | Engineering | 95000 | active | |
| Bob | Smith | Marketing | 72000 | active | |
| Carol | Williams | Sales | 68000 | active | |
| David | Brown | HR | 65000 | inactive | |
| Eva | Davis | Finance | 88000 | active | |
| Frank | Miller | Engineering | 102000 | active | |
| Grace | Wilson | Marketing | 76000 | active | |
| Henry | Taylor | Sales | 71000 | inactive | |
| Irene | Anderson | Engineering | 97000 | active | |
| James | Thomas | Finance | 91000 | active | |
| Karen | Jackson | HR | 63000 | active | |
| Leo | White | Engineering | 110000 | active | |
| Mia | Harris | Sales | 74000 | active | |
| Nathan | Martin | Marketing | 69000 | inactive | |
| Olivia | Garcia | Finance | 85000 | active | |
| Patrick | Martinez | Engineering | 99000 | active | |
| Quinn | Robinson | HR | 67000 | active | |
| Rachel | Clark | Sales | 73000 | active |
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')}
>
↑
</ActionIcon>
<ActionIcon
size="xs"
variant={row.getIsPinned() === 'bottom' ? 'filled' : 'default'}
onClick={() => row.pin(row.getIsPinned() === 'bottom' ? false : 'bottom')}
>
↓
</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 |
|---|---|---|---|---|---|---|
| Alice | Johnson | alice.johnson@example.com | Engineering | 95000 | 2021-03-15 | active |
| Bob | Smith | bob.smith@example.com | Marketing | 72000 | 2020-07-01 | active |
| Carol | Williams | carol.williams@example.com | Sales | 68000 | 2022-01-10 | active |
| David | Brown | david.brown@example.com | HR | 65000 | 2019-11-20 | inactive |
| Eva | Davis | eva.davis@example.com | Finance | 88000 | 2021-06-05 | active |
| Frank | Miller | frank.miller@example.com | Engineering | 102000 | 2018-09-12 | active |
| Grace | Wilson | grace.wilson@example.com | Marketing | 76000 | 2022-04-18 | active |
| Henry | Taylor | henry.taylor@example.com | Sales | 71000 | 2020-02-28 | inactive |
| Irene | Anderson | irene.anderson@example.com | Engineering | 97000 | 2021-08-30 | active |
| James | Thomas | james.thomas@example.com | Finance | 91000 | 2019-05-14 | active |
| Karen | Jackson | karen.jackson@example.com | HR | 63000 | 2023-01-09 | active |
| Leo | White | leo.white@example.com | Engineering | 110000 | 2017-12-01 | active |
| Mia | Harris | mia.harris@example.com | Sales | 74000 | 2022-07-22 | active |
| Nathan | Martin | nathan.martin@example.com | Marketing | 69000 | 2021-10-03 | inactive |
| Olivia | Garcia | olivia.garcia@example.com | Finance | 85000 | 2020-04-11 | active |
| Patrick | Martinez | patrick.martinez@example.com | Engineering | 99000 | 2019-08-25 | active |
| Quinn | Robinson | quinn.robinson@example.com | HR | 67000 | 2022-11-14 | active |
| Rachel | Clark | rachel.clark@example.com | Sales | 73000 | 2021-02-07 | active |
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 |
| Alice | Johnson | alice.johnson@example.com | Engineering | 95000 | active |
| Bob | Smith | bob.smith@example.com | Marketing | 72000 | active |
| Carol | Williams | carol.williams@example.com | Sales | 68000 | active |
| David | Brown | david.brown@example.com | HR | 65000 | inactive |
| Eva | Davis | eva.davis@example.com | Finance | 88000 | active |
| Frank | Miller | frank.miller@example.com | Engineering | 102000 | active |
| Grace | Wilson | grace.wilson@example.com | Marketing | 76000 | active |
| Henry | Taylor | henry.taylor@example.com | Sales | 71000 | inactive |
| Irene | Anderson | irene.anderson@example.com | Engineering | 97000 | active |
| James | Thomas | james.thomas@example.com | Finance | 91000 | active |
| Karen | Jackson | karen.jackson@example.com | HR | 63000 | active |
| Leo | White | leo.white@example.com | Engineering | 110000 | active |
| Mia | Harris | mia.harris@example.com | Sales | 74000 | active |
| Nathan | Martin | nathan.martin@example.com | Marketing | 69000 | inactive |
| Olivia | Garcia | olivia.garcia@example.com | Finance | 85000 | active |
| Patrick | Martinez | patrick.martinez@example.com | Engineering | 99000 | active |
| Quinn | Robinson | quinn.robinson@example.com | HR | 67000 | active |
| Rachel | Clark | rachel.clark@example.com | Sales | 73000 | active |
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-bodybackground. 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.