Use @sheetwrite/core directly when the host owns the DOM lifetime. You
initialize the engine, create the Grid, and destroy it yourself.
Package @sheetwrite/core
Entry points initSheetwrite, createGrid
Grid access The returned Grid
Change events grid.on("change")
Install
$ npm install @sheetwrite/core
Mount a grid
Call initSheetwrite() on the client, pass an existing element to createGrid,
and keep the returned Grid for events and commands.
} from "@sheetwrite/core" ;
export async function mountSheetwrite (
Listen to changes
grid.on("change", …) reports committed changes and returns a function that
removes the listener. The cleanup function in the example removes the listener
and then destroys the Grid.
Data and rendering
A datasource-backed Grid can use dense storage or allocation-lazy paged storage.
Full-sheet operations can throw IncompleteDataError until every required page
is loaded. Worker rendering falls back to the main-thread canvas when the
browser lacks a capability or the worker fails to start; listen to
renderer-fallback if the host must report that change.
function createGrid(host: HTMLElement, opts: GridOptions): Grid function createGrid (
host : HTMLElement ,
opts : GridOptions ,
) : Grid function createGrid (
host : HTMLElement ,
opts : GridOptions ,
) : Grid Creates and mounts an imperative Grid in the supplied host element. Example import { createGrid, initSheetwrite } from "@sheetwrite/core" ;
await initSheetwrite ();
const host = document. createElement ( "div" );
host.style.height = "400px" ;
document.body. append (host);
const grid = createGrid (host, {
workbook: {
activeSheet: "sales" ,
sheets: [{ id: "sales" , name: "Sales" , rowCount: 2 ,
columns: [{ key: "amount" , header: "Amount" , type: "number" , width: 120 }] }],
},
data: { rowCount: 2 , columns: { amount: [ 12 , 18 ] } },
});
grid. scrollToCell ({ sheet: "sales" , row: 1 , col: 0 });
// Call when the host view is removed.
grid. destroy (); See also Grid * See also GridOptions API reference → function initSheetwrite(source?: BufferSource | URL | string | Request | WebAssembly.Module, engine?: SheetwriteEngine): Promise<void> function initSheetwrite (
source ?:
BufferSource | URL | string | Request | WebAssembly . Module ,
engine ?: SheetwriteEngine ,
) : Promise < void > function initSheetwrite (
source ?:
| BufferSource
| URL
| string
| Request
| WebAssembly . Module ,
engine ?: SheetwriteEngine ,
) : Promise < void > Load one WASM engine before createGrid. The default is @sheetwrite/wasm. Pass the @sheetwrite/formulas module as the second argument to select the full engine. Example import { initSheetwrite } from "@sheetwrite/core" ;
import * as formulas from "@sheetwrite/formulas" ;
await initSheetwrite ( undefined , formulas); See also /docs/guides/formulas/ See also createGrid API reference → interface ChangeEvent interface ChangeEvent interface ChangeEvent Payload of the change event; flows OUT for API submission/reconcile. API reference → interface ColumnarData interface ColumnarData interface ColumnarData Eager column-oriented values used to initialize a sheet. API reference → interface Workbook interface Workbook interface Workbook Live workbook schema containing ordered sheets and the active sheet ID. API reference → function mountSheetwrite(host: HTMLElement, workbook: Workbook, data: ColumnarData, persistChange: (event: ChangeEvent) => void): Promise<() => void> function mountSheetwrite (
host : HTMLElement ,
workbook : Workbook ,
data : ColumnarData ,
persistChange : ( event : ChangeEvent ) => void ,
) : Promise <() => void > function mountSheetwrite (
host : HTMLElement ,
workbook : Workbook ,
data : ColumnarData ,
persistChange : (
event : ChangeEvent ,
) => void ,
) : Promise <() => void > interface HTMLElement interface HTMLElement interface HTMLElement The HTMLElement interface represents any HTML element. MDN Reference workbook: Workbook let workbook : Workbook let workbook : Workbook Live workbook schema adopted by the store and updated by document operations. API reference → data: ColumnarData let data : ColumnarData let data : ColumnarData Eager column-major values loaded into workbook.activeSheet; use instead of datasource. API reference → const grid: Grid const grid : Grid const grid : Grid The imperative core grid this controller owns. API reference → host: HTMLElement let host : HTMLElement let host : HTMLElement GridOptions.workbook: Workbook interface GridOptions {
workbook : Workbook ;
} interface GridOptions {
workbook : Workbook ;
} Live workbook schema adopted by the store and updated by document operations. API reference → GridOptions.data?: ColumnarData | undefined interface GridOptions {
data ?: ColumnarData | undefined ;
} interface GridOptions {
data ?: ColumnarData | undefined ;
} Eager column-major values loaded into workbook.activeSheet; use instead of datasource. API reference → const off: () => void const off : () => void const off : () => void Grid.on<"change">(evt: "change", fn: (e: ChangeEvent) => void): () => void Grid. on < "change" >(evt: "change" , fn: ( e : ChangeEvent ) => void ): () => void Grid. on < "change" >(evt: "change" , fn: ( e : ChangeEvent ) => void ): () => void persistChange: (event: ChangeEvent) => void let persistChange : ( event : ChangeEvent ) => void let persistChange : (
event : ChangeEvent ,
) => void API reference → Grid.destroy(): void Grid. destroy (): void Grid. destroy (): void Runs immediately before a retained element is removed or replaced. API reference →