# Pinning
Package: @mantine/data-grid
Import: import { Pinning } from '@mantine/data-grid';
Description: 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:

```tsx
// Demo.tsx
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>
  );
}

// data.ts
export const employees = [
  { id: '1', firstName: 'Alice', lastName: 'Johnson', email: 'alice.johnson@example.com', department: 'Engineering', salary: 95000, startDate: '2021-03-15', status: 'active' },
  { id: '2', firstName: 'Bob', lastName: 'Smith', email: 'bob.smith@example.com', department: 'Marketing', salary: 72000, startDate: '2020-07-01', status: 'active' },
  { id: '3', firstName: 'Carol', lastName: 'Williams', email: 'carol.williams@example.com', department: 'Sales', salary: 68000, startDate: '2022-01-10', status: 'active' },
  { id: '4', firstName: 'David', lastName: 'Brown', email: 'david.brown@example.com', department: 'HR', salary: 65000, startDate: '2019-11-20', status: 'inactive' },
  { id: '5', firstName: 'Eva', lastName: 'Davis', email: 'eva.davis@example.com', department: 'Finance', salary: 88000, startDate: '2021-06-05', status: 'active' },
  { id: '6', firstName: 'Frank', lastName: 'Miller', email: 'frank.miller@example.com', department: 'Engineering', salary: 102000, startDate: '2018-09-12', status: 'active' },
  { id: '7', firstName: 'Grace', lastName: 'Wilson', email: 'grace.wilson@example.com', department: 'Marketing', salary: 76000, startDate: '2022-04-18', status: 'active' },
  { id: '8', firstName: 'Henry', lastName: 'Taylor', email: 'henry.taylor@example.com', department: 'Sales', salary: 71000, startDate: '2020-02-28', status: 'inactive' },
  { id: '9', firstName: 'Irene', lastName: 'Anderson', email: 'irene.anderson@example.com', department: 'Engineering', salary: 97000, startDate: '2021-08-30', status: 'active' },
  { id: '10', firstName: 'James', lastName: 'Thomas', email: 'james.thomas@example.com', department: 'Finance', salary: 91000, startDate: '2019-05-14', status: 'active' },
  { id: '11', firstName: 'Karen', lastName: 'Jackson', email: 'karen.jackson@example.com', department: 'HR', salary: 63000, startDate: '2023-01-09', status: 'active' },
  { id: '12', firstName: 'Leo', lastName: 'White', email: 'leo.white@example.com', department: 'Engineering', salary: 110000, startDate: '2017-12-01', status: 'active' },
  { id: '13', firstName: 'Mia', lastName: 'Harris', email: 'mia.harris@example.com', department: 'Sales', salary: 74000, startDate: '2022-07-22', status: 'active' },
  { id: '14', firstName: 'Nathan', lastName: 'Martin', email: 'nathan.martin@example.com', department: 'Marketing', salary: 69000, startDate: '2021-10-03', status: 'inactive' },
  { id: '15', firstName: 'Olivia', lastName: 'Garcia', email: 'olivia.garcia@example.com', department: 'Finance', salary: 85000, startDate: '2020-04-11', status: 'active' },
  { id: '16', firstName: 'Patrick', lastName: 'Martinez', email: 'patrick.martinez@example.com', department: 'Engineering', salary: 99000, startDate: '2019-08-25', status: 'active' },
  { id: '17', firstName: 'Quinn', lastName: 'Robinson', email: 'quinn.robinson@example.com', department: 'HR', salary: 67000, startDate: '2022-11-14', status: 'active' },
  { id: '18', firstName: 'Rachel', lastName: 'Clark', email: 'rachel.clark@example.com', department: 'Sales', salary: 73000, startDate: '2021-02-07', status: 'active' },
];
```


## Pin multiple columns

Several columns can be pinned to each edge:

```tsx
// Demo.tsx
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>
  );
}

// data.ts
export const employees = [
  { id: '1', firstName: 'Alice', lastName: 'Johnson', email: 'alice.johnson@example.com', department: 'Engineering', salary: 95000, startDate: '2021-03-15', status: 'active' },
  { id: '2', firstName: 'Bob', lastName: 'Smith', email: 'bob.smith@example.com', department: 'Marketing', salary: 72000, startDate: '2020-07-01', status: 'active' },
  { id: '3', firstName: 'Carol', lastName: 'Williams', email: 'carol.williams@example.com', department: 'Sales', salary: 68000, startDate: '2022-01-10', status: 'active' },
  { id: '4', firstName: 'David', lastName: 'Brown', email: 'david.brown@example.com', department: 'HR', salary: 65000, startDate: '2019-11-20', status: 'inactive' },
  { id: '5', firstName: 'Eva', lastName: 'Davis', email: 'eva.davis@example.com', department: 'Finance', salary: 88000, startDate: '2021-06-05', status: 'active' },
  { id: '6', firstName: 'Frank', lastName: 'Miller', email: 'frank.miller@example.com', department: 'Engineering', salary: 102000, startDate: '2018-09-12', status: 'active' },
  { id: '7', firstName: 'Grace', lastName: 'Wilson', email: 'grace.wilson@example.com', department: 'Marketing', salary: 76000, startDate: '2022-04-18', status: 'active' },
  { id: '8', firstName: 'Henry', lastName: 'Taylor', email: 'henry.taylor@example.com', department: 'Sales', salary: 71000, startDate: '2020-02-28', status: 'inactive' },
  { id: '9', firstName: 'Irene', lastName: 'Anderson', email: 'irene.anderson@example.com', department: 'Engineering', salary: 97000, startDate: '2021-08-30', status: 'active' },
  { id: '10', firstName: 'James', lastName: 'Thomas', email: 'james.thomas@example.com', department: 'Finance', salary: 91000, startDate: '2019-05-14', status: 'active' },
  { id: '11', firstName: 'Karen', lastName: 'Jackson', email: 'karen.jackson@example.com', department: 'HR', salary: 63000, startDate: '2023-01-09', status: 'active' },
  { id: '12', firstName: 'Leo', lastName: 'White', email: 'leo.white@example.com', department: 'Engineering', salary: 110000, startDate: '2017-12-01', status: 'active' },
  { id: '13', firstName: 'Mia', lastName: 'Harris', email: 'mia.harris@example.com', department: 'Sales', salary: 74000, startDate: '2022-07-22', status: 'active' },
  { id: '14', firstName: 'Nathan', lastName: 'Martin', email: 'nathan.martin@example.com', department: 'Marketing', salary: 69000, startDate: '2021-10-03', status: 'inactive' },
  { id: '15', firstName: 'Olivia', lastName: 'Garcia', email: 'olivia.garcia@example.com', department: 'Finance', salary: 85000, startDate: '2020-04-11', status: 'active' },
  { id: '16', firstName: 'Patrick', lastName: 'Martinez', email: 'patrick.martinez@example.com', department: 'Engineering', salary: 99000, startDate: '2019-08-25', status: 'active' },
  { id: '17', firstName: 'Quinn', lastName: 'Robinson', email: 'quinn.robinson@example.com', department: 'HR', salary: 67000, startDate: '2022-11-14', status: 'active' },
  { id: '18', firstName: 'Rachel', lastName: 'Clark', email: 'rachel.clark@example.com', department: 'Sales', salary: 73000, startDate: '2021-02-07', status: 'active' },
];
```


## 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:

```tsx
// Demo.tsx
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>
  );
}

// data.ts
export const employees = [
  { id: '1', firstName: 'Alice', lastName: 'Johnson', email: 'alice.johnson@example.com', department: 'Engineering', salary: 95000, startDate: '2021-03-15', status: 'active' },
  { id: '2', firstName: 'Bob', lastName: 'Smith', email: 'bob.smith@example.com', department: 'Marketing', salary: 72000, startDate: '2020-07-01', status: 'active' },
  { id: '3', firstName: 'Carol', lastName: 'Williams', email: 'carol.williams@example.com', department: 'Sales', salary: 68000, startDate: '2022-01-10', status: 'active' },
  { id: '4', firstName: 'David', lastName: 'Brown', email: 'david.brown@example.com', department: 'HR', salary: 65000, startDate: '2019-11-20', status: 'inactive' },
  { id: '5', firstName: 'Eva', lastName: 'Davis', email: 'eva.davis@example.com', department: 'Finance', salary: 88000, startDate: '2021-06-05', status: 'active' },
  { id: '6', firstName: 'Frank', lastName: 'Miller', email: 'frank.miller@example.com', department: 'Engineering', salary: 102000, startDate: '2018-09-12', status: 'active' },
  { id: '7', firstName: 'Grace', lastName: 'Wilson', email: 'grace.wilson@example.com', department: 'Marketing', salary: 76000, startDate: '2022-04-18', status: 'active' },
  { id: '8', firstName: 'Henry', lastName: 'Taylor', email: 'henry.taylor@example.com', department: 'Sales', salary: 71000, startDate: '2020-02-28', status: 'inactive' },
  { id: '9', firstName: 'Irene', lastName: 'Anderson', email: 'irene.anderson@example.com', department: 'Engineering', salary: 97000, startDate: '2021-08-30', status: 'active' },
  { id: '10', firstName: 'James', lastName: 'Thomas', email: 'james.thomas@example.com', department: 'Finance', salary: 91000, startDate: '2019-05-14', status: 'active' },
  { id: '11', firstName: 'Karen', lastName: 'Jackson', email: 'karen.jackson@example.com', department: 'HR', salary: 63000, startDate: '2023-01-09', status: 'active' },
  { id: '12', firstName: 'Leo', lastName: 'White', email: 'leo.white@example.com', department: 'Engineering', salary: 110000, startDate: '2017-12-01', status: 'active' },
  { id: '13', firstName: 'Mia', lastName: 'Harris', email: 'mia.harris@example.com', department: 'Sales', salary: 74000, startDate: '2022-07-22', status: 'active' },
  { id: '14', firstName: 'Nathan', lastName: 'Martin', email: 'nathan.martin@example.com', department: 'Marketing', salary: 69000, startDate: '2021-10-03', status: 'inactive' },
  { id: '15', firstName: 'Olivia', lastName: 'Garcia', email: 'olivia.garcia@example.com', department: 'Finance', salary: 85000, startDate: '2020-04-11', status: 'active' },
  { id: '16', firstName: 'Patrick', lastName: 'Martinez', email: 'patrick.martinez@example.com', department: 'Engineering', salary: 99000, startDate: '2019-08-25', status: 'active' },
  { id: '17', firstName: 'Quinn', lastName: 'Robinson', email: 'quinn.robinson@example.com', department: 'HR', salary: 67000, startDate: '2022-11-14', status: 'active' },
  { id: '18', firstName: 'Rachel', lastName: 'Clark', email: 'rachel.clark@example.com', department: 'Sales', salary: 73000, startDate: '2021-02-07', status: 'active' },
];
```


## Row pinning

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

```tsx
// Demo.tsx
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} />;
}

// data.ts
export const employees = [
  { id: '1', firstName: 'Alice', lastName: 'Johnson', email: 'alice.johnson@example.com', department: 'Engineering', salary: 95000, startDate: '2021-03-15', status: 'active' },
  { id: '2', firstName: 'Bob', lastName: 'Smith', email: 'bob.smith@example.com', department: 'Marketing', salary: 72000, startDate: '2020-07-01', status: 'active' },
  { id: '3', firstName: 'Carol', lastName: 'Williams', email: 'carol.williams@example.com', department: 'Sales', salary: 68000, startDate: '2022-01-10', status: 'active' },
  { id: '4', firstName: 'David', lastName: 'Brown', email: 'david.brown@example.com', department: 'HR', salary: 65000, startDate: '2019-11-20', status: 'inactive' },
  { id: '5', firstName: 'Eva', lastName: 'Davis', email: 'eva.davis@example.com', department: 'Finance', salary: 88000, startDate: '2021-06-05', status: 'active' },
  { id: '6', firstName: 'Frank', lastName: 'Miller', email: 'frank.miller@example.com', department: 'Engineering', salary: 102000, startDate: '2018-09-12', status: 'active' },
  { id: '7', firstName: 'Grace', lastName: 'Wilson', email: 'grace.wilson@example.com', department: 'Marketing', salary: 76000, startDate: '2022-04-18', status: 'active' },
  { id: '8', firstName: 'Henry', lastName: 'Taylor', email: 'henry.taylor@example.com', department: 'Sales', salary: 71000, startDate: '2020-02-28', status: 'inactive' },
  { id: '9', firstName: 'Irene', lastName: 'Anderson', email: 'irene.anderson@example.com', department: 'Engineering', salary: 97000, startDate: '2021-08-30', status: 'active' },
  { id: '10', firstName: 'James', lastName: 'Thomas', email: 'james.thomas@example.com', department: 'Finance', salary: 91000, startDate: '2019-05-14', status: 'active' },
  { id: '11', firstName: 'Karen', lastName: 'Jackson', email: 'karen.jackson@example.com', department: 'HR', salary: 63000, startDate: '2023-01-09', status: 'active' },
  { id: '12', firstName: 'Leo', lastName: 'White', email: 'leo.white@example.com', department: 'Engineering', salary: 110000, startDate: '2017-12-01', status: 'active' },
  { id: '13', firstName: 'Mia', lastName: 'Harris', email: 'mia.harris@example.com', department: 'Sales', salary: 74000, startDate: '2022-07-22', status: 'active' },
  { id: '14', firstName: 'Nathan', lastName: 'Martin', email: 'nathan.martin@example.com', department: 'Marketing', salary: 69000, startDate: '2021-10-03', status: 'inactive' },
  { id: '15', firstName: 'Olivia', lastName: 'Garcia', email: 'olivia.garcia@example.com', department: 'Finance', salary: 85000, startDate: '2020-04-11', status: 'active' },
  { id: '16', firstName: 'Patrick', lastName: 'Martinez', email: 'patrick.martinez@example.com', department: 'Engineering', salary: 99000, startDate: '2019-08-25', status: 'active' },
  { id: '17', firstName: 'Quinn', lastName: 'Robinson', email: 'quinn.robinson@example.com', department: 'HR', salary: 67000, startDate: '2022-11-14', status: 'active' },
  { id: '18', firstName: 'Rachel', lastName: 'Clark', email: 'rachel.clark@example.com', department: 'Sales', salary: 73000, startDate: '2021-02-07', status: 'active' },
];
```


## 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:

```tsx
// Demo.tsx
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} />;
}

// data.ts
export const employees = [
  { id: '1', firstName: 'Alice', lastName: 'Johnson', email: 'alice.johnson@example.com', department: 'Engineering', salary: 95000, startDate: '2021-03-15', status: 'active' },
  { id: '2', firstName: 'Bob', lastName: 'Smith', email: 'bob.smith@example.com', department: 'Marketing', salary: 72000, startDate: '2020-07-01', status: 'active' },
  { id: '3', firstName: 'Carol', lastName: 'Williams', email: 'carol.williams@example.com', department: 'Sales', salary: 68000, startDate: '2022-01-10', status: 'active' },
  { id: '4', firstName: 'David', lastName: 'Brown', email: 'david.brown@example.com', department: 'HR', salary: 65000, startDate: '2019-11-20', status: 'inactive' },
  { id: '5', firstName: 'Eva', lastName: 'Davis', email: 'eva.davis@example.com', department: 'Finance', salary: 88000, startDate: '2021-06-05', status: 'active' },
  { id: '6', firstName: 'Frank', lastName: 'Miller', email: 'frank.miller@example.com', department: 'Engineering', salary: 102000, startDate: '2018-09-12', status: 'active' },
  { id: '7', firstName: 'Grace', lastName: 'Wilson', email: 'grace.wilson@example.com', department: 'Marketing', salary: 76000, startDate: '2022-04-18', status: 'active' },
  { id: '8', firstName: 'Henry', lastName: 'Taylor', email: 'henry.taylor@example.com', department: 'Sales', salary: 71000, startDate: '2020-02-28', status: 'inactive' },
  { id: '9', firstName: 'Irene', lastName: 'Anderson', email: 'irene.anderson@example.com', department: 'Engineering', salary: 97000, startDate: '2021-08-30', status: 'active' },
  { id: '10', firstName: 'James', lastName: 'Thomas', email: 'james.thomas@example.com', department: 'Finance', salary: 91000, startDate: '2019-05-14', status: 'active' },
  { id: '11', firstName: 'Karen', lastName: 'Jackson', email: 'karen.jackson@example.com', department: 'HR', salary: 63000, startDate: '2023-01-09', status: 'active' },
  { id: '12', firstName: 'Leo', lastName: 'White', email: 'leo.white@example.com', department: 'Engineering', salary: 110000, startDate: '2017-12-01', status: 'active' },
  { id: '13', firstName: 'Mia', lastName: 'Harris', email: 'mia.harris@example.com', department: 'Sales', salary: 74000, startDate: '2022-07-22', status: 'active' },
  { id: '14', firstName: 'Nathan', lastName: 'Martin', email: 'nathan.martin@example.com', department: 'Marketing', salary: 69000, startDate: '2021-10-03', status: 'inactive' },
  { id: '15', firstName: 'Olivia', lastName: 'Garcia', email: 'olivia.garcia@example.com', department: 'Finance', salary: 85000, startDate: '2020-04-11', status: 'active' },
  { id: '16', firstName: 'Patrick', lastName: 'Martinez', email: 'patrick.martinez@example.com', department: 'Engineering', salary: 99000, startDate: '2019-08-25', status: 'active' },
  { id: '17', firstName: 'Quinn', lastName: 'Robinson', email: 'quinn.robinson@example.com', department: 'HR', salary: 67000, startDate: '2022-11-14', status: 'active' },
  { id: '18', firstName: 'Rachel', lastName: 'Clark', email: 'rachel.clark@example.com', department: 'Sales', salary: 73000, startDate: '2021-02-07', status: 'active' },
];
```


## Combined row and column pinning

Row pinning and column pinning can be used together:

```tsx
// Demo.tsx
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>
  );
}

// data.ts
export const employees = [
  { id: '1', firstName: 'Alice', lastName: 'Johnson', email: 'alice.johnson@example.com', department: 'Engineering', salary: 95000, startDate: '2021-03-15', status: 'active' },
  { id: '2', firstName: 'Bob', lastName: 'Smith', email: 'bob.smith@example.com', department: 'Marketing', salary: 72000, startDate: '2020-07-01', status: 'active' },
  { id: '3', firstName: 'Carol', lastName: 'Williams', email: 'carol.williams@example.com', department: 'Sales', salary: 68000, startDate: '2022-01-10', status: 'active' },
  { id: '4', firstName: 'David', lastName: 'Brown', email: 'david.brown@example.com', department: 'HR', salary: 65000, startDate: '2019-11-20', status: 'inactive' },
  { id: '5', firstName: 'Eva', lastName: 'Davis', email: 'eva.davis@example.com', department: 'Finance', salary: 88000, startDate: '2021-06-05', status: 'active' },
  { id: '6', firstName: 'Frank', lastName: 'Miller', email: 'frank.miller@example.com', department: 'Engineering', salary: 102000, startDate: '2018-09-12', status: 'active' },
  { id: '7', firstName: 'Grace', lastName: 'Wilson', email: 'grace.wilson@example.com', department: 'Marketing', salary: 76000, startDate: '2022-04-18', status: 'active' },
  { id: '8', firstName: 'Henry', lastName: 'Taylor', email: 'henry.taylor@example.com', department: 'Sales', salary: 71000, startDate: '2020-02-28', status: 'inactive' },
  { id: '9', firstName: 'Irene', lastName: 'Anderson', email: 'irene.anderson@example.com', department: 'Engineering', salary: 97000, startDate: '2021-08-30', status: 'active' },
  { id: '10', firstName: 'James', lastName: 'Thomas', email: 'james.thomas@example.com', department: 'Finance', salary: 91000, startDate: '2019-05-14', status: 'active' },
  { id: '11', firstName: 'Karen', lastName: 'Jackson', email: 'karen.jackson@example.com', department: 'HR', salary: 63000, startDate: '2023-01-09', status: 'active' },
  { id: '12', firstName: 'Leo', lastName: 'White', email: 'leo.white@example.com', department: 'Engineering', salary: 110000, startDate: '2017-12-01', status: 'active' },
  { id: '13', firstName: 'Mia', lastName: 'Harris', email: 'mia.harris@example.com', department: 'Sales', salary: 74000, startDate: '2022-07-22', status: 'active' },
  { id: '14', firstName: 'Nathan', lastName: 'Martin', email: 'nathan.martin@example.com', department: 'Marketing', salary: 69000, startDate: '2021-10-03', status: 'inactive' },
  { id: '15', firstName: 'Olivia', lastName: 'Garcia', email: 'olivia.garcia@example.com', department: 'Finance', salary: 85000, startDate: '2020-04-11', status: 'active' },
  { id: '16', firstName: 'Patrick', lastName: 'Martinez', email: 'patrick.martinez@example.com', department: 'Engineering', salary: 99000, startDate: '2019-08-25', status: 'active' },
  { id: '17', firstName: 'Quinn', lastName: 'Robinson', email: 'quinn.robinson@example.com', department: 'HR', salary: 67000, startDate: '2022-11-14', status: 'active' },
  { id: '18', firstName: 'Rachel', lastName: 'Clark', email: 'rachel.clark@example.com', department: 'Sales', salary: 73000, startDate: '2021-02-07', status: 'active' },
];
```


## 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:

```tsx
// Demo.tsx
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>
  );
}

// data.ts
export const employees = [
  { id: '1', firstName: 'Alice', lastName: 'Johnson', email: 'alice.johnson@example.com', department: 'Engineering', salary: 95000, startDate: '2021-03-15', status: 'active' },
  { id: '2', firstName: 'Bob', lastName: 'Smith', email: 'bob.smith@example.com', department: 'Marketing', salary: 72000, startDate: '2020-07-01', status: 'active' },
  { id: '3', firstName: 'Carol', lastName: 'Williams', email: 'carol.williams@example.com', department: 'Sales', salary: 68000, startDate: '2022-01-10', status: 'active' },
  { id: '4', firstName: 'David', lastName: 'Brown', email: 'david.brown@example.com', department: 'HR', salary: 65000, startDate: '2019-11-20', status: 'inactive' },
  { id: '5', firstName: 'Eva', lastName: 'Davis', email: 'eva.davis@example.com', department: 'Finance', salary: 88000, startDate: '2021-06-05', status: 'active' },
  { id: '6', firstName: 'Frank', lastName: 'Miller', email: 'frank.miller@example.com', department: 'Engineering', salary: 102000, startDate: '2018-09-12', status: 'active' },
  { id: '7', firstName: 'Grace', lastName: 'Wilson', email: 'grace.wilson@example.com', department: 'Marketing', salary: 76000, startDate: '2022-04-18', status: 'active' },
  { id: '8', firstName: 'Henry', lastName: 'Taylor', email: 'henry.taylor@example.com', department: 'Sales', salary: 71000, startDate: '2020-02-28', status: 'inactive' },
  { id: '9', firstName: 'Irene', lastName: 'Anderson', email: 'irene.anderson@example.com', department: 'Engineering', salary: 97000, startDate: '2021-08-30', status: 'active' },
  { id: '10', firstName: 'James', lastName: 'Thomas', email: 'james.thomas@example.com', department: 'Finance', salary: 91000, startDate: '2019-05-14', status: 'active' },
  { id: '11', firstName: 'Karen', lastName: 'Jackson', email: 'karen.jackson@example.com', department: 'HR', salary: 63000, startDate: '2023-01-09', status: 'active' },
  { id: '12', firstName: 'Leo', lastName: 'White', email: 'leo.white@example.com', department: 'Engineering', salary: 110000, startDate: '2017-12-01', status: 'active' },
  { id: '13', firstName: 'Mia', lastName: 'Harris', email: 'mia.harris@example.com', department: 'Sales', salary: 74000, startDate: '2022-07-22', status: 'active' },
  { id: '14', firstName: 'Nathan', lastName: 'Martin', email: 'nathan.martin@example.com', department: 'Marketing', salary: 69000, startDate: '2021-10-03', status: 'inactive' },
  { id: '15', firstName: 'Olivia', lastName: 'Garcia', email: 'olivia.garcia@example.com', department: 'Finance', salary: 85000, startDate: '2020-04-11', status: 'active' },
  { id: '16', firstName: 'Patrick', lastName: 'Martinez', email: 'patrick.martinez@example.com', department: 'Engineering', salary: 99000, startDate: '2019-08-25', status: 'active' },
  { id: '17', firstName: 'Quinn', lastName: 'Robinson', email: 'quinn.robinson@example.com', department: 'HR', salary: 67000, startDate: '2022-11-14', status: 'active' },
  { id: '18', firstName: 'Rachel', lastName: 'Clark', email: 'rachel.clark@example.com', department: 'Sales', salary: 73000, startDate: '2021-02-07', status: 'active' },
];
```


## 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:

```tsx
<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:

```tsx
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:

```tsx
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:

```tsx
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.
