Pin rows to the top or bottom
Some rows must stay visible while you scroll. The first few rows can be pinned by count with pinnedRows: 3 (see Data and rows); this page covers pinning by row key, the bottom zone and external rows outside the data. Everything is optional, and without it nothing changes. It does not work together with paging, a tree or grouping.
| Name | What it does |
|---|---|
api.pinRow(key, where?) | Pin a row to 'top' (default) or 'bottom'. true when something changed, false for an unknown key, a row that cannot be pinned, or one already there |
api.unpinRow(key) | Unpin a row pinned by key; true when it was unpinned |
api.getPinnedRows() | { top, bottom } row arrays: count-pinned, key-pinned and external rows in display order |
api.isRowPinned(key) | 'top', 'bottom' or null |
isRowPinnable(row, key) | Whether a row may be pinned (default all). false blocks pinRow and the menu |
pinnedRows.menu | With true, the cell menu gets pin and unpin items |
pinnedRows.top pinnedRows.bottom | External rows outside the data |
Event pinnedRowsChanged | { top, bottom } keys of data rows; external rows have no key and are left out |
const api = createGrid(el, { columns, rows, rowKey: 'id', pinnedRows: { count: 0, menu: true } });
api.pinRow(42); // top
api.pinRow(7, 'bottom'); // bottomRows pinned by key
A pin follows the key, not the position. Sorting, filtering and setRows keep a pinned row in its zone, and when the row disappears the pin is dropped silently (pinnedRowsChanged fires). A pinned row stays visible in its zone even if the filter would hide it. Pinned rows leave the body flow, and selection, editing and focus work as on any row. The top zone stacks rows in the order they were pinned, and rows pinned by count come after them. The line order is [top pins, first N rows, body, bottom pins], so export and copy use that order, and aria-rowindex runs through it.
External rows
Rows in pinnedRows: { count: 0, top: [...], bottom: [...] } are not data. They are not counted, not sorted, filtered, selected or edited (read-only), and need no key. Each cell draws only the text made by formatValue (no cell renderers or menus). They suit totals or reference values that must always show. In getPinnedRows() external rows come first in the top zone and last in the bottom zone.
Menu
With pinnedRows.menu: true the cell menu gets "Pin row to top", "Pin row to bottom" and "Unpin row". Rows blocked by isRowPinnable get no pin items. The menu text follows the locale (ko, en).
Gotchas
- Using
pagination,treeorgroupingtogether withpinnedRows.top,bottom,menuorisRowPinnablethrowsinvalid-option(a count-onlypinnedRowsis still switched off silently as before).pinRowalso throwsinvalid-optionthen. - External rows are not merged and not exported (export writes data rows only).
- Rows pinned by key count in
getPinnedRowCount()(top plus bottom).