Skip to content

SpreadsheetEngine API

SpreadsheetEngine is the central orchestrator that creates and wires all subsystems. It is the single entry point for programmatic control of the spreadsheet.

import { SpreadsheetEngine } from '@witqq/spreadsheet';
const engine = new SpreadsheetEngine({
columns,
data,
editable: true,
theme: lightTheme,
});
engine.mount(document.getElementById('grid')!);
MethodSignatureDescription
mount(container: HTMLElement) => voidMount engine into DOM container, create canvas, attach events
destroy() => voidDestroy engine, remove canvas, detach all event listeners
render() => voidForce immediate re-render of the entire canvas
requestRender() => voidSchedule re-render on next animation frame
MethodSignatureDescription
getCell(row, col) => CellData | undefinedGet cell data at logical row/col
setCell(row, col, value) => voidSet cell value at logical row/col
bulkLoadCellData(data, startRow?) => voidBulk load 2D array of CellData objects
getCellStore() => CellStoreAccess the underlying CellStore

Cell styles are applied through the CellStore and a standalone StylePool instance:

import { StylePool } from '@witqq/spreadsheet';
const cellStore = engine.getCellStore();
const stylePool = new StylePool();
const ref = stylePool.intern({
fontWeight: 'bold',
bgColor: '#fef3cd',
borderBottom: { width: 1, color: '#856404', style: 'solid' },
});
const style = stylePool.resolve(ref)!;
cellStore.set(row, col, {
value: 'Warning',
style: { ref, style },
});

StylePool is not part of SpreadsheetEngine — create and manage it alongside the engine. The CellData.style field holds a CellStyleRef with the dedup key and resolved style.

See Per-Cell Styling for CellStyle properties, borders, alignment, and number formatting.

MethodSignatureDescription
setCellStatus(row, col, status, errorMessage?) => voidSet cell tracking status
getCellStatus(row, col) => CellMetadata['status'] | undefinedGet cell tracking status
getChangedCells() => Array<{row, col}>Get all cells with ‘changed’ status
getChangeTracker() => ChangeTrackerAccess the ChangeTracker instance
MethodSignatureDescription
getRowStore() => RowStoreAccess RowStore for row heights
setRowHeight(row, height) => voidSet a specific row height
getLayoutEngine() => LayoutEngine | nullAccess cumulative position arrays
MethodSignatureDescription
getSelection() => SelectionGet current selection state
getSelectionManager() => SelectionManagerAccess SelectionManager
getKeyboardNavigator() => KeyboardNavigator | nullAccess keyboard navigation
MethodSignatureDescription
getCommandManager() => CommandManagerAccess undo/redo stack
MethodSignatureDescription
getSortColumns() => readonly SortColumn[]Get current sort state
getSortEngine() => SortEngineAccess SortEngine
MethodSignatureDescription
setColumnFilter(col, conditions) => voidSet filter on column
removeColumnFilter(col) => voidRemove filter from column
clearFilters() => voidRemove all filters
getFilteredRowCount() => numberNumber of visible rows after filtering
getFilterEngine() => FilterEngineAccess FilterEngine
openFilterPanel(col) => voidOpen filter panel UI for column
closeFilterPanel() => voidClose filter panel
isFilterPanelOpenboolean (getter)Whether filter panel is open
MethodSignatureDescription
mergeCells(region, value?) => booleanMerge cells in region (false if invalid)
unmergeCells(startRow, startCol) => booleanUnmerge cells at anchor (false if none)
getMergedRegion(row, col) => MergedRegion | nullGet merged region containing cell
getMergeManager() => MergeManagerAccess MergeManager
MethodSignatureDescription
setRowGroups(groups: RowGroupDef[]) => voidDefine row groups
toggleRowGroup(logicalRow) => voidToggle expand/collapse
expandAllGroups() => voidExpand all groups
collapseAllGroups() => voidCollapse all groups
clearRowGroups() => voidRemove all groups
setGroupAggregates(aggregates) => voidSet aggregate functions for group headers
getRowGroupManager() => RowGroupManagerAccess RowGroupManager
MethodSignatureDescription
setColumnValidation(col, rules) => voidSet validation rules for column
setCellValidation(row, col, rules) => voidSet validation rules for cell
removeColumnValidation(col) => voidRemove column validation
removeCellValidation(row, col) => voidRemove cell validation
getValidationEngine() => ValidationEngineAccess ValidationEngine
MethodSignatureDescription
registerContextMenuItem(item: ContextMenuItem) => voidRegister a menu item
unregisterContextMenuItem(id: string) => voidRemove a menu item
getContextMenuManager() => ContextMenuManager | nullAccess ContextMenuManager
MethodSignatureDescription
getClipboardManager() => ClipboardManager | nullAccess ClipboardManager
MethodSignatureDescription
getInlineEditor() => InlineEditor | nullAccess InlineEditor
MethodSignatureDescription
addRenderLayer(layer) => voidAppend a render layer
insertRenderLayerBefore(layer, beforeLayer) => voidInsert layer before another
getRenderLayer<T>(layerClass) => T | undefinedGet layer by class
removeRenderLayer(layer) => voidRemove a render layer
MethodSignatureDescription
getTheme() => SpreadsheetThemeGet current theme
setTheme(theme: SpreadsheetTheme) => voidSwitch theme at runtime
MethodSignatureDescription
installPlugin(plugin: SpreadsheetPlugin) => voidInstall a plugin (checks dependencies)
removePlugin(name: string) => voidRemove plugin by name
getPlugin(name: string) => SpreadsheetPlugin | undefinedGet installed plugin
MethodSignatureDescription
on(event, handler) => voidSubscribe to an event
off(event, handler) => voidUnsubscribe from an event
getEventBus() => EventBusAccess the EventBus

See Event System for a full list of events.

MethodSignatureDescription
getVisibleRange() => CellRangeGet currently visible row/col range
getDataView() => DataViewAccess logical↔physical row mapping
getViewportManager() => ViewportManager | nullAccess viewport calculation
getDirtyTracker() => DirtyTracker | nullAccess dirty tracking
getScrollManager() => ScrollManager | nullAccess scroll container
getConfig() => SpreadsheetEngineConfigGet engine configuration
getCanvasElement() => HTMLCanvasElement | nullGet the canvas DOM element
getCellTypeRegistry() => CellTypeRegistryAccess cell type registry

Register decorators via getCellTypeRegistry() to render icons or indicators around cell text.

engine.getCellTypeRegistry().addDecorator({
decorator: {
id: 'status-dot',
position: 'left',
getWidth: () => 16,
render: (ctx, cellData, x, y, w, h) => {
ctx.beginPath();
ctx.arc(x + w / 2, y + h / 2, 4, 0, Math.PI * 2);
ctx.fillStyle = cellData.value === 'Active' ? '#63be7b' : '#999';
ctx.fill();
},
getHitZones: (w, h) => [{ id: 'dot', x: 0, y: 0, width: w, height: h, cursor: 'pointer' }],
},
appliesTo: (row, col) => col === 5,
});
engine.getCellTypeRegistry().removeDecorator('status-dot');

Cell events include hitZone and hitZoneCursor when the click lands on a decorator or renderer hit zone:

engine.on('cellClick', (event) => {
if (event.hitZone === 'dot') {
console.log('Decorator clicked at row', event.row);
}
});