Skip to content

Cell Spans

Declare rectangular cell spans across ordered real body rows and consecutive columns within the same pin partition and page.

Rectangular Cell Spans
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();
};
}
  • Declaration (CellSpan): { spanId, anchor: { row, colId }, rows: [...], colIds: [...] }. Resolve row addresses on the current page via grid.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; check grid.getCellSpanState() and cellSpansChanged.
  • 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,000 span declarations, 100 × 100 (10,000 cells) per span, and 100,000 total spanned cells. Overlapping or invalid spans reject atomically.