Skip to content

Row Height & Density

NextGrid keeps JS virtualization geometry and CSS row heights synchronized through grid options and indexed prefix-sum offsets.

Variable Row Heights & Header Height
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 columnDefs: readonly ColumnDef<OrderRow>[] = [
{
key: 'id',
name: 'ID',
width: 96,
pinned: 'start',
},
{
key: 'customer',
name: 'Customer',
width: 175,
flex: 1,
},
{
key: 'product',
name: 'Product',
width: 185,
flex: 1,
},
{
key: 'amount',
name: 'Amount',
width: 115,
cellDataType: 'number',
formatter: ({ value }) =>
`$${Number(value).toLocaleString('en-US')}`,
},
];
const grid = new Grid<OrderRow>({
container: stage,
columnDefs,
rowData: createOrders(30),
getRowId: (row) => row.id,
headerRowHeight: 34,
variableRowHeights: {
getHeight: (params) =>
params.kind === 'data' && params.sourceIndex % 3 === 0 ? 44 : 28,
},
});
const stopTheme = syncGridTheme(stage);
addButton(controls, 'Reset heights', () => {
grid.resetRowHeights();
meta.textContent = 'Row heights recalculated';
});
meta.textContent = 'Variable heights: 44px every 3rd row, 28px others';
return () => {
grid.destroy();
stopTheme();
};
}
Option Default Description
rowHeight 26 (22 in compact) Uniform body row height in px; overrides density
density 'default' 'compact' sets 22 px body rows and 26 px header rows
headerRowHeight 30 (26 in compact) Single header row height in px (grouped headers stack per level); overrides --next-grid-header-row-height
variableRowHeights false RowHeightOptions<T> (getHeight(params)) for per-row heights
rowHeightBounds { minHeight: 8, maxHeight: 100000 } Clamps calculated or measured row heights
  • Call grid.resetRowHeights(addresses?) to invalidate cached measured heights (all rows when omitted, or specific RowHeightAddress entries) and trigger re-measurement on the next frame.
  • Full-width and detail rows configure intrinsic measurement via fullWidthHeight and detail options (HeightParams receives kind: 'data' | 'pinned' | 'synthetic').