Cell Spans
Declare rectangular cell spans across ordered real body rows and consecutive columns within the same pin partition and page.
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(20);
const columnDefs: readonly ColumnDef<OrderRow>[] = [ { key: 'id', name: 'ID', width: 96, }, { key: 'customer', name: 'Customer', width: 170, flex: 1, }, { key: 'region', name: 'Region', width: 110, }, { key: 'status', name: 'Status', width: 110, }, ];
const grid = new Grid<OrderRow>({ container: stage, columnDefs, rowData: rows, getRowId: (row) => row.id, }); const stopTheme = syncGridTheme(stage);
const applyDemoSpan = () => { const first = grid.getRowAddress(0); const second = grid.getRowAddress(1); if (!first || !second) return; grid.setCellSpans([ { spanId: 'dispatch-block', anchor: { row: first, colId: 'customer', }, rows: [first, second], colIds: ['customer', 'region'], }, ]); };
const updateMeta = () => { const st = grid.getCellSpanState(); meta.textContent = `Active spans: ${st.active.length} · Suppressed: ${st.suppressed.length}`; }; grid.addEventListener('cellSpansChanged', updateMeta); applyDemoSpan();
addButton(controls, 'Apply 2×2 span', applyDemoSpan); addButton(controls, 'Clear spans', () => grid.setCellSpans([])); updateMeta();
return () => { grid.destroy(); stopTheme(); };}Rules, Suppression & Limits
Section titled “Rules, Suppression & Limits”- Declaration (
CellSpan):{ spanId, anchor: { row, colId }, rows: [...], colIds: [...] }. Resolve row addresses on the current page viagrid.getRowAddress(displayIndex). - Suppression (
CellSpanSuppressionReason): Sorting, filtering, paging, column reorder/hide/pinning across partitions, or inserting full-width/detail rows inside a span suspends it cleanly without losing the declaration; checkgrid.getCellSpanState()andcellSpansChanged. - Editing & Clipboard: Focus and editing resolve covered cells to
anchor. Copy emits the anchor value with empty covered TSV slots; paste, fill, and delete require selecting the full span rectangle. - Limits: At most
1,000span declarations,100 × 100(10,000cells) per span, and100,000total spanned cells. Overlapping or invalid spans reject atomically.