Skip to content

Events

Grid events, their payloads, and which events carry committed document changes.
On this page

grid.on(evt, fn) subscribes to a grid event and returns an off() function. Call it to unsubscribe.

Observe committed changes
const off = grid.on("change", ({ transaction, source, commitReason }) => {
if (source === "local") console.log(commitReason, transaction.patches.length);
});
// later
off();

After a user types a value and presses Enter, the log shows edit-enter 1.

Event direction

change is the committed transaction stream. ChangeEvent.source is local for user or API output that a host may persist, and remote for already-persisted input that must not be enqueued again. Selection, search, renderer fallback, and other UI events remain observational.

Framework onGridChange / grid-change callbacks carry the same committed event. Adapter readiness is { grid, generation, reason }; reason distinguishes initial, input-reset, and renderer-reset. The imperative ref, exposed handle, or binding is assigned before readiness and cleared on replacement.

Grid events

EventPayload
changeChangeEvent: { transaction; changes; commitReason; source: "local" | "remote"; epoch? }
selection{ selection: Selection | null }
scroll{ scrollTop; firstRow; lastRow; scrollLeft; firstVisibleColumn; lastVisibleColumn }; the visible-column fields are number | null.
edit-begin{ addr: CellAddress }
edit-commit{ addr: CellAddress; value: CellValue }
searchSearchResult: { query: string; matches: CellAddress[]; active: number }
command-state-change{ states }: every command's GridCommandState. See Host-owned command state.
mutation-rejected{ issues: MutationIssue[] }
active-sheet{ sheet: SheetId }, after the visible sheet changes (direct call or cross-sheet scroll).
hyperlink-activateHyperlinkActivationEvent
theme-change{ theme: Theme }, after setTheme or replaceTheme changes the base theme.
renderer-fallback{ requested: "worker"; error: SheetwriteError }, once, when the worker renderer could not be constructed.
datasource-error{ request; error: SheetwriteError }; request is the DataSourceRequest without its signal.
export-error{ format: "csv" | "xlsx"; error: SheetwriteError }, when a built-in toolbar or context-menu export fails.

commitReason is one of edit-blur, edit-enter, edit-tab, edit-programmatic, paste, cut, clear, fill, structure, style, replace, undo, redo or api.

Sync coordinator events

SyncCoordinator has its own event stream. sync.on(fn) returns an unsubscribe function:

Sync events
documentId: "products",
});
const off = sync.on((event) => {
if (event.type === "conflict") showConflict(event.response);
if (event.type === "reload-required") requestFreshSnapshot();
});
saveButton.onclick = () => void sync.sendNext();
// later
off();
event.typePayload
statestate
restoredpending
persisting, pending, sendingmutation
acknowledgedclientMutationId, version, duplicate
conflictmutation, response
remote-appliedoperation
reload-requiredexpectedVersion, receivedVersion, optional snapshot
reloaded, recoveredserverVersion, pending
storage-error, errorerror, optional clientMutationId

Edge cases and limits

  • Persist only change events with source: "local". Remote input is observable but never belongs in outgoing local persistence.
  • changes is empty for commits that only change metadata.
  • Hydration from a snapshot and datasource pages emit no user change event.

See also

Documentation