Skip to content

Data grid - Column pinning

Pin columns to keep them visible at all time.

Pinned (or frozen, locked, or sticky) columns are columns that are visible at all time while the user scrolls the grid horizontally. They can be pinned either to the left or right side and cannot be reordered.

To pin a column, there are a few ways:

  • Using the initialState prop
  • Controlling the pinnedColumns and onPinnedColumnsChange props
  • Dedicated buttons in the column menu
  • Accessing the imperative API

To set pinned columns via initialState, pass an object with the following shape to this prop:

interface GridPinnedColumns {
  left?: string[]; // Optional field names to pin to the left
  right?: string[]; // Optional field names to pin to the right
}

The following demos illustrates how this approach works:

Name
Email
Age
Date Created
Last Login
Scott McKenzie
Myrtle Weaver
Gilbert Simmons
Maggie Dawson
Louisa Stanley
Jennie Ballard
Gussie Underwood
Alfred Carpenter
Robert Burke
fubolu@zip.cl
25
12/4/2024
4/8/2025, 1:30:35 AM
zi@few.kz
36
12/8/2024
4/7/2025, 1:05:07 PM
zicjib@pazzudkuc.bn
19
10/14/2024
4/7/2025, 11:49:18 AM
wuzub@jeiniuk.ws
28
3/21/2025
4/8/2025, 3:12:42 AM
nezi@nouvno.cx
23
3/9/2025
4/7/2025, 4:09:52 PM
zodle@di.sc
27
7/24/2024
4/7/2025, 9:29:39 PM
kaoke@tivitru.su
18
12/31/2024
4/7/2025, 10:18:30 AM
hitti@lecrewuh.ve
31
5/30/2024
4/7/2025, 10:23:49 PM
naljer@laufe.vn
24
10/9/2024
4/7/2025, 9:46:26 PM
Total Rows: 10
Press Enter to start editing

Controlling the pinned columns

While the initialState prop only works for setting pinned columns during the initialization, the pinnedColumns prop allows you to modify which columns are pinned at any time. The value passed to it follows the same shape from the previous approach. Use it together with onPinnedColumnsChange to know when a column is pinned or unpinned.

Name
Email
Age
Date Created
Last Login
Hulda Shaw
Cynthia Greer
Craig McGuire
Katharine Thompson
Maud Moore
aduico@pu.gu
25
10/29/2024
4/8/2025, 12:33:42 AM
ohiko@de.tm
36
7/4/2024
4/8/2025, 2:56:46 AM
zu@nu.ee
19
9/12/2024
4/7/2025, 9:41:21 PM
fi@sevsaoc.ci
28
7/1/2024
4/7/2025, 9:53:28 PM
wablokzof@howuk.gb
23
5/5/2024
4/7/2025, 7:59:21 PM
Total Rows: 5
Press Enter to start editing

Blocking column unpinning

It may be desirable to not allow a column to be unpinned. The only thing required to achieve that is to hide the buttons added to the column menu. This can be done in two ways:

  1. Per column, by setting pinnable to false in each GridColDef:

    <DataGrid columns={[{ field: 'id', pinnable: false }]} /> // Default is `true`.
    
  2. By providing a custom menu, as demonstrated below:

Name
Email
Age
Date Created
Last Login
Bruce Logan
Larry Cooper
Amelia Mack
Derrick Meyer
Nannie Gilbert
kob@ju.gl
25
9/17/2024
4/7/2025, 2:41:44 PM
eginad@pa.gt
36
10/9/2024
4/7/2025, 6:11:27 PM
satiba@soggec.tt
19
2/1/2025
4/7/2025, 9:09:55 AM
cijimec@zep.tc
28
5/22/2024
4/8/2025, 1:24:28 AM
ubahazken@sup.sy
23
3/16/2025
4/7/2025, 8:04:27 PM
Total Rows: 5
Press Enter to start editing

Pinning the checkbox selection column

To pin the checkbox column added when using checkboxSelection, add GRID_CHECKBOX_SELECTION_COL_DEF.field to the list of pinned columns.

Name
Email
Age
Date Created
Last Login
Jeremy Gutierrez
ecrepda@ganujuhe.gt
25
9/25/2024
4/8/2025, 7:05:55 AM
Clara Haynes
pa@turwembur.net
36
3/18/2025
4/7/2025, 3:51:23 PM
Harold Murray
alvo@keinu.id
19
6/24/2024
4/7/2025, 6:42:07 PM
Lida Guzman
ucgik@culu.bh
28
9/3/2024
4/7/2025, 11:44:49 AM
Jonathan Wade
hezleko@opo.us
23
7/4/2024
4/7/2025, 1:23:19 PM
Total Rows: 5
Press Enter to start editing

Usage with dynamic row height

You can have both pinned columns and dynamic row height enabled at the same time. However, if the rows change their content after the initial calculation, you may need to trigger a manual recalculation to avoid incorrect measurements. You can do this by calling apiRef.current.resetRowHeights() every time that the content changes.

The demo below contains an example of both features enabled:

Name
Email
Age
Date Created
Last Login
Actions
Mabel Dawson
Christine Rodriguez
Lida Porter
Mary Cole
Gregory Robertson
Joshua Hawkins
Allie Hubbard
Celia Patrick
Edwin Reese
narbedjot@suf.ao
25
5/10/2024
4/7/2025, 3:30:32 PM
neruc@fibwodfo.ca
36
5/13/2024
4/8/2025, 2:00:30 AM
ok@jukincej.np
19
2/13/2025
4/8/2025, 7:30:43 AM
beeza@tezimhe.kp
28
1/23/2025
4/7/2025, 7:09:28 PM
tutnud@sorhul.za
23
1/7/2025
4/8/2025, 12:22:21 AM
lad@odnuc.ni
27
1/3/2025
4/7/2025, 9:19:32 PM
je@nuhmab.ge
18
5/20/2024
4/7/2025, 6:45:58 PM
de@jizi.ax
31
1/17/2025
4/7/2025, 10:12:45 PM
esfod@fif.nl
24
8/10/2024
4/8/2025, 3:19:35 AM
Total Rows: 10
Press Enter to start editing

apiRef

Signature:
getPinnedColumns: () => GridPinnedColumns
Signature:
isColumnPinned: (field: string) => GridPinnedPosition | false
Signature:
pinColumn: (field: string, side: GridPinnedPosition) => void
Signature:
setPinnedColumns: (pinnedColumns: GridPinnedColumns) => void
Signature:
unpinColumn: (field: string) => void