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:

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.

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:

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.

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:

Press Enter to start editing


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.

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