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 data 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
Grace Howell
Mabelle Hughes
Marion Vasquez
Amy Marshall
Oscar Cain
Troy Cannon
Logan Kennedy
Linnie Osborne
Elijah Wade
nowsekkuj@jeszu.bb
25
5/28/2024
5/4/2025, 9:35:35 AM
fofucuha@jah.gq
36
10/15/2024
5/4/2025, 12:53:35 PM
cucoji@bobofo.bt
19
12/3/2024
5/4/2025, 1:12:54 AM
edof@riciddi.tp
28
9/19/2024
5/4/2025, 3:03:20 PM
uh@nu.mw
23
8/2/2024
5/4/2025, 5:53:42 AM
iwwes@waut.ls
27
6/26/2024
5/4/2025, 12:04:05 AM
wucga@joizu.cr
18
4/20/2025
5/4/2025, 4:44:22 AM
eniha@odweli.jp
31
10/13/2024
5/4/2025, 1:30:34 PM
etozacros@aloefu.bz
24
11/27/2024
5/4/2025, 8:45:55 AM
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
Lloyd Perry
Olivia Dixon
Randall Jenkins
Franklin Huff
Gavin Mack
feli@izo.ru
25
9/22/2024
5/4/2025, 7:41:52 AM
ihical@soer.mu
36
12/31/2024
5/4/2025, 12:04:08 PM
wewwesgah@tolokja.ws
19
11/1/2024
5/4/2025, 1:07:07 PM
pupaw@fenuwco.mm
28
6/5/2024
5/4/2025, 7:33:30 PM
mi@ugewawuna.ch
23
7/24/2024
5/4/2025, 5:50:21 AM
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
George Davidson
Dean Pena
Corey Campbell
Betty Cooper
Linnie Gardner
reskoki@cu.com
25
6/12/2024
5/4/2025, 5:41:17 PM
meedkaz@mopfuz.fr
36
6/24/2024
5/4/2025, 2:00:12 PM
fut@vefighu.hm
19
6/2/2024
5/4/2025, 6:55:01 AM
go@so.gov
28
8/24/2024
5/4/2025, 4:07:11 AM
erovamup@zigi.sa
23
6/9/2024
5/4/2025, 9:13:29 AM
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
Rosalie Quinn
ruw@pid.sm
25
3/4/2025
5/3/2025, 9:57:07 PM
Christina Mann
ca@us.hr
36
3/22/2025
5/3/2025, 8:02:19 PM
Lola Wade
kilajten@tufov.wf
19
9/15/2024
5/4/2025, 5:03:42 PM
Leila Fuller
dunlukco@satsegon.sd
28
10/24/2024
5/4/2025, 8:13:37 AM
John Cook
sidhiwak@zodjag.fi
23
9/22/2024
5/4/2025, 3:16:35 AM
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
Troy Haynes
Addie Perez
Maurice McCoy
Marvin Griffin
Pauline Dunn
Eunice Cunningham
gi@wodfo.vn
25
11/22/2024
5/4/2025, 5:27:00 AM
ta@wiunusi.lt
36
10/9/2024
5/3/2025, 8:29:48 PM
izoucwib@ubvozri.gi
19
5/20/2024
5/4/2025, 1:46:00 PM
geicuhe@no.ci
28
8/1/2024
5/4/2025, 9:25:03 AM
oji@go.bd
23
11/16/2024
5/4/2025, 11:25:30 AM
sa@ra.dj
27
11/24/2024
5/4/2025, 10:41:37 AM
Total Rows: 10
Press Enter to start editing

apiRef

The grid exposes a set of methods that enables all of these features using the imperative apiRef. To know more about how to use it, check the API Object section.

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