View as Markdown

Frozen Rows and Columns

Pinned rows

Pin records to the top of the grid by data or at runtime; pinned rows follow sorting, filtering and edits and stay outside the page size.

Pinned rows are records shown in a fixed zone above the scrolling rows. Unlike stickyRows, which keeps the first N positions of the view in place, pinning follows the record: a pinned order stays on top whatever the sort, page or scroll position.

Pinning rows

isRowPinned(row) pins rows by data. It must be pure; the grid reads it when it is created and calls it once per row of a data array, again only for rows that are added or changed, so edits that make a row match pin it.

defaultPinnedRows pins rows by id when the grid is created. Either prop turns pinning on; pass defaultPinnedRows={[]} to pin only from code.

<DataGrid
  data={orders}
  columns={columns}
  isRowPinned={(order) => order.priority === 'High'}
  ref={api}
/>

api.current?.pinRows(['ORD-1042']);
api.current?.unpinRows('ORD-1042');
api.current?.isRowPinned('ORD-1042'); // false
api.current?.getPinnedRowIds();      // pinned rows shown, in display order

unpinRows also unpins rows that isRowPinned matches, and pinRows undoes that. Rows are identified by their row id, so the grid needs a primaryKey column or getRowId.

Sorting, filtering, paging and editing

  • A pinned row is shown once: it leaves its place among the scrolling rows.
  • Pinned rows are sorted among themselves by the current sort.
  • A pinned row that the filter or search excludes is hidden, and comes back pinned when the filter changes.
  • Pinned rows are not counted in pageSize or the page count: every page shows the pinned rows above its own rows.
  • Edits, adds and deletes update pinned rows like any other row.
  • Footer aggregates include the pinned rows (the page-wise footer counts the pinned rows and the page). Select all selects them too.
  • While grouping, pinned rows stay above the groups and belong to none; pinned rows show no detail toggle or detail row (see Detail rows).
  • Pinned rows are neither drag sources nor drop targets for row drag (see Row drag).

Layout, keyboard and accessibility

Pinned rows render first in the sticky top rowgroup, followed by the stickyRows rows, and carry data-pinned. The virtual row window never contains them, and pinned columns intersect them like any row. Their aria-rowindex follows the visible order, so arrow keys move from the last pinned row to the first scrolling row and back.

State and export

getState() stores the pins and unpins made by id under pinnedRows (rows pinned by isRowPinned need no state), and restoreState() applies them; exclude the part with exclude: ['pinnedRows']. Ungrouped exports list the pinned rows first, as the grid shows them.

With a remote data source the grid can only pin rows the server returned for the current page.

Pinned rows

Open demo

Rows pinned by isRowPinned and at runtime with api.pinRows / api.unpinRows stay in the sticky top zone of 2,000 virtualized orders, follow sorting, filtering and search, and stay outside pageSize.

Order
Customer
Country
Product
Priority
Qty
Amount
ORD-10002
Jun Park
France
Kettle
High
10
$616.55
ORD-10005
Goran Petrov
France
Oolong tea
High
7
$84.79
ORD-10010
Dewi Lestari
France
Green tea
High
4
$33.30
ORD-10000
Dewi Lestari
Malaysia
Filter beans
Low
8
$106.40
ORD-10001
Dewi Lestari
France
Filter beans
Normal
9
$107.10
ORD-10003
Hana Sato
Germany
Espresso beans
Low
8
$140.60
ORD-10004
Hana Sato
Malaysia
Grinder
Normal
1
$109.65
ORD-10006
Goran Petrov
Germany
Kettle
Low
12
$739.86
ORD-10007
Aiko Tan
France
Grinder
Low
12
$1,470.60
ORD-10008
Aiko Tan
Japan
Grinder
Low
9
$1,161.00
ORD-10009
Dewi Lestari
France
Green tea
Normal
10
$92.50
ORD-10011
Hana Sato
Germany
Kettle
Low
5
$324.50
ORD-10012
Farah Aziz
Portugal
Grinder
High
10
$1,161.00
ORD-10013
Ines Duarte
Malaysia
Kettle
Normal
2
$110.33
ORD-10014
Elif Kaya
Malaysia
Grinder
High
5
$580.50
ORD-10015
Dewi Lestari
France
Pour-over kit
Low
5
$178.50
ORD-10016
Goran Petrov
Malaysia
Pour-over kit
Normal
11
$438.90
ORD-10017
Farah Aziz
France
Filter beans
Normal
3
$37.80
ORD-10018
Jun Park
Portugal
Grinder
Normal
1
$109.65
ORD-10019
Hana Sato
Malaysia
Green tea
Normal
5
$41.63

Pinned rows shown: none

API reference

DataGridProps lists isRowPinned and defaultPinnedRows, and DataGridApi pinRows, unpinRows, isRowPinned and getPinnedRowIds.