MRT logoMantine React Table

On This Page

Column Pinning Feature Guide

Column pinning is a cool feature that lets users pin (freeze) columns to the left or right of the table. Pinned columns will not scroll horizontally with the rest of the columns so that they always stay visible to the user.

Relevant Table Options

#
Prop Name
Type
Default Value
More Info Links
1boolean
2OnChangeFn<ColumnPinningState>TanStack Table Column Pinning Docs

Relevant Column Options

#
Column Option
Type
Default Value
More Info Links

No records to display

Relevant State

#
State Option
Type
Default Value
More Info Links
1{ left: Array<string>, right: Array<string> }{ left: [], right: [] }TanStack Table Column Pinning Docs

Enable Column Pinning

Column pinning can simply be enabled by setting the enableColumnPinning table option to true.

const table = useMantineReactTable({
  data,
  columns,
  enableColumnPinning: true,
});

Pin (Freeze) Columns By Default

Columns can start out pinned in your table by setting the columnPinning states in either initialState or state.

const table = useMantineReactTable({
  data,
  columns,
  enableColumnPinning: true,
  initialState: {
    columnPinning: {
      left: ['email'], //pin email column to left by default
      right: ['mrt-row-actions'], //pin built-in row actions display column to right by default
    },
  },
});

Column Pinning Example

State
ID
First Name
Middle Name
Last Name
Address
City
Kentucky1DylanSprouseMurray261 Erdman FordEast Daphne
Ohio2RaquelHakeemKohler769 Dominic GroveColumbus
West Virginia3ErvinKrisReinger566 Brakus InletSouth Linda
Nebraska4BrittanyKathrynMcCullough722 Emie StreamLincoln
South Carolina5BransonJohnFrami32188 Larkin TurnpikeCharleston

Rows per page

1-5 of 5

import '@mantine/core/styles.css';
import '@mantine/dates/styles.css'; //if using mantine date picker features
import 'mantine-react-table/styles.css'; //make sure MRT styles were imported in your app root (once)
import { useMemo } from 'react';
import { MantineReactTable, type MRT_ColumnDef } from 'mantine-react-table';
import { data, type Person } from './makeData';

const Example = () => {
  const columns = useMemo<MRT_ColumnDef<Person>[]>(
    () => [
      {
        accessorKey: 'id',
        enableColumnPinning: false, //disable column pinning for this column
        header: 'ID',
        size: 50,
      },
      {
        accessorKey: 'firstName',
        header: 'First Name',
      },
      {
        accessorKey: 'middleName',
        header: 'Middle Name',
      },
      {
        accessorKey: 'lastName',
        header: 'Last Name',
      },
      {
        accessorKey: 'address',
        header: 'Address',
        size: 300,
      },
      {
        accessorKey: 'city', //this column gets pinned to the right by default because of the initial state,
        header: 'City',
      },

      {
        accessorKey: 'state', //this column gets pinned left by default because of the the initial state,
        header: 'State',
      },
    ],
    [],
  );

  return (
    <MantineReactTable
      columns={columns}
      data={data}
      enableColumnPinning
      initialState={{ columnPinning: { left: ['state'], right: ['city'] } }}
    />
  );
};

export default Example;