Skip to content

Pinned Rows & Totals

Pinned rows remain fixed above or below the vertically scrollable body while scrolling horizontally in lockstep with center and pinned columns.

Top & Bottom Pinned Rows
import { Grid, type ColumnDef } from 'next-grid-js';
import { createOrders, type OrderRow } from './data/orders';
import { syncGridTheme } from './theme';
import type { DemoMountContext } from './types';
import { addButton } from './ui';
export function mount({
stage,
controls,
meta,
}: DemoMountContext): () => void {
const rows = createOrders(30);
const columnDefs: readonly ColumnDef<OrderRow>[] = [
{
key: 'id',
name: 'ID',
width: 96,
pinned: 'start',
},
{
key: 'customer',
name: 'Customer',
width: 175,
flex: 1,
},
{
key: 'quantity',
name: 'Qty',
width: 85,
cellDataType: 'number',
},
{
key: 'amount',
name: 'Amount',
width: 120,
cellDataType: 'number',
formatter: ({ value }) =>
`$${Number(value).toLocaleString('en-US')}`,
},
];
const topPin = [
{
id: 'pin-top-1',
data: {
...rows[0],
id: 'TARGET',
customer: 'Monthly Quota Target',
quantity: 500,
amount: 150000,
},
},
];
const bottomPin = [
{
id: 'pin-bot-1',
data: {
...rows[0],
id: 'TOTAL',
customer: `All ${rows.length} Orders`,
quantity: rows.reduce((s, r) => s + r.quantity, 0),
amount: rows.reduce((s, r) => s + r.amount, 0),
},
},
];
const grid = new Grid<OrderRow>({
container: stage,
columnDefs,
rowData: rows,
getRowId: (row) => row.id,
pinnedRows: {
top: topPin,
bottom: bottomPin,
},
});
const stopTheme = syncGridTheme(stage);
addButton(controls, 'Clear pins', () => {
grid.clearPinnedRows();
meta.textContent = 'Top: 0 · Bottom: 0';
});
addButton(controls, 'Restore pins', () => {
grid.setPinnedRows('top', topPin);
grid.setPinnedRows('bottom', bottomPin);
meta.textContent = 'Top: 1 · Bottom: 1';
});
meta.textContent = 'Top: 1 · Bottom: 1';
return () => {
grid.destroy();
stopTheme();
};
}
  • Supplied Rows (pinnedRows): Pass { top, bottom } of { id, data } items at construction or replace dynamically with grid.setPinnedRows('top' | 'bottom', rows) and grid.clearPinnedRows(). Use pinnedCellRenderer on ColumnDef<T> to customize cells in pinned regions.
  • Projected Totals (pinnedTotals): Pass { group?, grand?, placement: 'copy' | 'move' } (or setPinnedTotals) to project hierarchy or pivot totals into pinned regions. 'copy' keeps the body total; 'move' removes it from body/page counts.
  • Bounds & Recovery: Each region supports up to 100 entries across supplied and projected rows. Commands exceeding minBodyHeight (80 px default) reject; external container shrinks expose a Clear pinned rows button in the footer.