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
Raymond Washington
Ina Higgins
Mittie Baldwin
Clara Gordon
Glen Logan
Albert Reese
Gerald McBride
Winnie Taylor
Gerald Ellis
pas@tur.zm
25
8/16/2024
4/5/2025, 8:03:15 AM
huah@fimrec.ac
36
1/8/2025
4/6/2025, 12:09:44 AM
huoklom@ivane.bn
19
12/25/2024
4/5/2025, 8:19:14 AM
fe@cu.im
28
10/29/2024
4/6/2025, 1:06:53 AM
kebviwi@fa.us
23
5/24/2024
4/5/2025, 9:30:38 PM
akosila@edfo.mc
27
8/11/2024
4/6/2025, 12:39:04 AM
obizitfuf@deji.vg
18
4/4/2025
4/5/2025, 9:47:28 PM
hicu@cuikemo.ss
31
10/14/2024
4/5/2025, 3:55:05 PM
toceknok@esgag.hu
24
1/20/2025
4/5/2025, 9:08:13 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
Francisco Hicks
Gavin Bowers
Jason McBride
Rosa Hanson
Jeffrey Walker
neg@eki.uy
25
7/14/2024
4/5/2025, 11:57:10 AM
doizojav@izuijahef.pr
36
8/26/2024
4/5/2025, 3:41:40 PM
rit@len.am
19
9/10/2024
4/5/2025, 4:30:02 PM
futera@wagu.al
28
2/11/2025
4/5/2025, 10:32:41 AM
kebol@kanas.cz
23
2/22/2025
4/6/2025, 4:10:23 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
Rosetta Townsend
Micheal Aguilar
Susan Maxwell
Roger Goodman
Peter Lindsey
vufzinge@ji.tf
25
7/26/2024
4/6/2025, 1:10:40 AM
fup@zumido.nu
36
7/28/2024
4/5/2025, 3:19:56 PM
urmas@wuzpe.cx
19
12/20/2024
4/5/2025, 4:46:06 PM
nouc@rosu.gb
28
9/22/2024
4/6/2025, 3:30:40 AM
liluto@fek.ps
23
10/12/2024
4/6/2025, 12:08:20 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
Dennis Lindsey
dijtu@lec.sb
25
9/22/2024
4/5/2025, 2:09:41 PM
Sallie Doyle
nitokha@egcir.sm
36
11/4/2024
4/5/2025, 3:59:47 PM
Jesus Holland
leh@hahle.co.uk
19
1/21/2025
4/6/2025, 12:43:07 AM
Frederick Austin
ru@nub.is
28
12/2/2024
4/5/2025, 9:00:17 AM
James Patterson
kumfufrop@bupaddi.ck
23
9/16/2024
4/5/2025, 2:42:21 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
Keith Abbott
Stephen Valdez
Lettie Tyler
Bettie Phelps
Lilly Carroll
Etta Schmidt
Gregory Marsh
Olive Vega
Herbert Baker
ugseco@gaclu.tf
25
11/2/2024
4/6/2025, 6:32:35 AM
itki@iba.iq
36
7/5/2024
4/5/2025, 12:44:19 PM
loglok@umrezim.bo
19
8/4/2024
4/5/2025, 8:18:22 AM
kal@nip.edu
28
9/1/2024
4/6/2025, 1:28:05 AM
cuj@baf.dm
23
2/8/2025
4/5/2025, 8:26:03 AM
mewhov@hecda.kw
27
1/1/2025
4/6/2025, 12:45:00 AM
voha@ob.pf
18
2/11/2025
4/5/2025, 3:22:02 PM
law@zovese.mn
31
6/10/2024
4/6/2025, 5:26:22 AM
zojfomun@imodod.se
24
5/6/2024
4/5/2025, 11:38:45 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