createSelectionStatus(host, grid) appends an <output role="status"> with the class sheetwrite-shell-status to host and returns a ShellPiece: element is the <output>, and destroy() removes it and stops its listeners. Import @sheetwrite/core/shell.css for the shell styles.
What it shows
Part
When it shows
Average
Two or more selected cells hold values, and at least one of them is a number.
Count
Two or more selected cells hold values. Text and errors count.
Sum
Two or more selected cells hold values, and at least one of them is a number.
Selection size
A range shows rows × columns cells, a row shows Row n, a column shows Column n, and a multi selection shows n ranges. A single cell shows nothing.
The parts are joined with ·. When there is nothing to show, the <output> is hidden, and so is its host when the status bar is the host's only child.
The status bar updates on each selection and change event. It is a polite live region, so screen readers announce changes without interrupting the user.
Read the totals yourself
grid.summarizeSelection(signal?) returns the totals that the status bar uses. Use it to build your own status bar, or to show Min and Max.
With B1:B3 from the first example selected, this logs Min: 4 · Max: 12.
Options
createSelectionStatus and createSpreadsheetShell have no status bar options. These are the fields of the SelectionSummary that summarizeSelection resolves:
Field
Type
Meaning
count
number
Cells that hold any value, including text and errors.
numericCount
number
Cells that hold a number. Dates are numbers too.
sum
number
Sum of the numeric cells.
average
number | null
Mean of the numeric cells; null when there are none.
min
number | null
Smallest number; null when there are none.
max
number | null
Largest number; null when there are none.
summarizeSelection resolves null when nothing is selected.
Edge cases and limits
The totals cover only the cells the user can see. Rows that a filter hides are left out.
Overlapping ranges in a multi selection count once per range, as in Excel.
Whole-row selections stop at the last column; there are no cells past it.
Large selections are read in chunks of 65,536 cells, with a pause between frames, so the page stays responsive. In one measurement, 4 million cells took about 160 ms in total and at most 10 ms per chunk.
Abort the signal to stop early. The promise then rejects with the signal's reason. The status bar aborts an unfinished summary when the selection or the data changes.
The totals use the selection and the active sheet as they were when the call started.
function createSpreadsheetShell(host: HTMLElement, options: SpreadsheetShellOptions): SpreadsheetShellfunctioncreateSpreadsheetShell(host:HTMLElement,options:SpreadsheetShellOptions,):SpreadsheetShellfunctioncreateSpreadsheetShell(host:HTMLElement,options:SpreadsheetShellOptions,):SpreadsheetShellMount a complete spreadsheet shell into host: toolbar row, formula row (name box + formula bar), the grid, and a bottom row with sheet tabs and a selection status. The host must have a real size; the shell fills it. Returns the shell handle; destroy tears down every piece, the grid, and the shell DOM, and is safe to call twice.API reference →const shell: SpreadsheetShellconstshell:SpreadsheetShellconstshell:SpreadsheetShellAPI reference →type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : anytypeReturnType<Textends (...args:any) =>any> =Textends (...args:any) =>inferR?R:any;typeReturnType<Textends (...args:any) =>any,> =Textends (...args:any) =>inferR?R:any;Obtain the return type of a function typeSpreadsheetShell.grid: GridinterfaceSpreadsheetShell {grid:Grid;}interfaceSpreadsheetShell {grid:Grid;}The single grid the shell owns; use it for data, search, and actions.API reference →Grid.setSelection(sel: Selection | null): voidGrid.setSelection(sel: Selection |null): voidGrid.setSelection(sel: Selection |null): voidkind: "range"let kind:"range"let kind:"range"Selects one inclusive rectangular range.range: Rangelet range:Rangelet range:RangeData-space bounds of the selected rectangle.API reference →Range.sheet: stringinterfaceRange {sheet:string;}interfaceRange {sheet:string;}Sheet identity used by the simple data-first adapter. Defaults to sheet1.API reference →Range.start: {
row: number;
col: number;
}interfaceRange {start: {row:number;col:number;};}interfaceRange {start: {row:number;col:number;};}Zero-based workbook column index of the first key.API reference →row: numberlet row:numberlet row:number0-based row of the cell that holds the top-left corner.API reference →col: numberlet col:numberlet col:number0-based column of the cell that holds the top-left corner.API reference →Range.end: {
row: number;
col: number;
}interfaceRange {end: {row:number;col:number;};}interfaceRange {end: {row:number;col:number;};}Exclusive workbook column index after the last key.API reference →function initSheetwrite(source?: BufferSource | URL | string | Request | WebAssembly.Module, engine?: SheetwriteEngine): Promise<void>functioninitSheetwrite(source?:BufferSource|URL|string|Request|WebAssembly.Module,engine?:SheetwriteEngine,):Promise<void>functioninitSheetwrite(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.Exampleimport { initSheetwrite } from"@sheetwrite/core";import*as formulas from"@sheetwrite/formulas";awaitinitSheetwrite(undefined, formulas);See also/docs/start/choose-an-engine/See alsocreateGridAPI reference →interface ColumnarDatainterfaceColumnarDatainterfaceColumnarDataEager column-oriented values used to initialize a sheet.API reference →interface WorkbookinterfaceWorkbookinterfaceWorkbookLive workbook schema containing ordered sheets and the active sheet ID.API reference →const host: HTMLElement | nullconsthost:HTMLElement|nullconsthost:HTMLElement|nullvar document: Documentvar document:Documentvar document:Documentwindow.document returns a reference to the document contained in the window. MDN ReferenceAPI reference →ParentNode.querySelector<HTMLElement>(selectors: string): HTMLElement | null (+4 overloads)ParentNode.querySelector<HTMLElement>(selectors: string): HTMLElement |null (+4 overloads)ParentNode.querySelector<HTMLElement>(selectors: string): HTMLElement |null (+4 overloads)Returns the first element that is a descendant of node that matches selectors. MDN Referenceinterface HTMLElementinterfaceHTMLElementinterfaceHTMLElementThe HTMLElement interface represents any HTML element. MDN Referencevar Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+2 overloads)var Error:ErrorConstructornew (message?:string, options?:ErrorOptions) =>Error (+2 overloads)var Error:ErrorConstructornew (message?:string, options?:ErrorOptions) =>Error (+2 overloads)const host: HTMLElementconsthost:HTMLElementconsthost:HTMLElementElementCSSInlineStyle.style: CSSStyleDeclarationinterfaceElementCSSInlineStyle {style:CSSStyleDeclaration;}interfaceElementCSSInlineStyle {style:CSSStyleDeclaration;}MDN ReferenceAPI reference →CSSStyleDeclaration.height: stringinterfaceCSSStyleDeclaration {height:string;}interfaceCSSStyleDeclaration {height:string;}MDN ReferenceAPI reference →const workbook: Workbookconstworkbook:Workbookconstworkbook:WorkbookLive workbook schema adopted by the store and updated by document operations.API reference →Workbook.activeSheet: stringinterfaceWorkbook {activeSheet:string;}interfaceWorkbook {activeSheet:string;}Active sheet ID and initial tab presented when the grid is created.API reference →Workbook.sheets: Sheet[]interfaceWorkbook {sheets:Sheet[];}interfaceWorkbook {sheets:Sheet[];}Sheets in display/tab order.API reference →Sheet.id: stringinterfaceSheet {id:string;}interfaceSheet {id:string;}Stable identifier, unique within the workbook and used by every cell address.API reference →Sheet.name: stringinterfaceSheet {name:string;}interfaceSheet {name:string;}User-facing sheet name shown in tabs and workbook exports.API reference →Sheet.rowCount: numberinterfaceSheet {rowCount:number;}interfaceSheet {rowCount:number;}Row count for both in-memory and datasource-backed sheets.API reference →Sheet.columns: Column[]interfaceSheet {columns:Column[];}interfaceSheet {columns:Column[];}Ordered schema; array positions are the zero-based column coordinates.API reference →Column.key: stringinterfaceColumn {key:string;}interfaceColumn {key:string;}Non-empty key, unique within the sheet, used to map input and datasource values.API reference →Column.header: stringinterfaceColumn {header:string;}interfaceColumn {header:string;}Schema label used by table exports and data-grid presentation headers.API reference →Column.width: numberinterfaceColumn {width:number;}interfaceColumn {width:number;}Unzoomed column width in CSS pixels.API reference →Column.type: CellFormatinterfaceColumn {type:CellFormat;}interfaceColumn {type:CellFormat;}Controls cell input parsing and default value formatting for this column.API reference →const data: ColumnarDataconstdata:ColumnarDataconstdata:ColumnarDataEager column-major values loaded into workbook.activeSheet; use instead of datasource.API reference →ColumnarData.rowCount: numberinterfaceColumnarData {rowCount:number;}interfaceColumnarData {rowCount:number;}Row count for both in-memory and datasource-backed sheets.API reference →ColumnarData.columns: Record<string, ArrayLike<CellScalar | CellValue>>interfaceColumnarData {columns:Record<string, ArrayLike<CellScalar|CellValue>>;}interfaceColumnarData {columns:Record<string,ArrayLike<CellScalar|CellValue>>;}Exact column runs represented by every returned row.API reference →product: string[]let product:string[]let product:string[]amount: Float64Array<ArrayBuffer>let amount:Float64Array<ArrayBuffer>let amount:Float64Array<ArrayBuffer>var Float64Array: Float64ArrayConstructor
new (elements: Iterable<number>) => Float64Array<ArrayBuffer> (+6 overloads)var Float64Array:Float64ArrayConstructornew (elements:Iterable<number>) =>Float64Array<ArrayBuffer> (+6 overloads)var Float64Array:Float64ArrayConstructornew (elements:Iterable<number>) =>Float64Array<ArrayBuffer> (+6 overloads)SpreadsheetShellOptions.grid: GridOptionsinterfaceSpreadsheetShellOptions {grid:GridOptions;}interfaceSpreadsheetShellOptions {grid:GridOptions;}Options for the single grid the shell owns. initSheetwrite must already be awaited.API reference →GridOptions.workbook: WorkbookinterfaceGridOptions {workbook:Workbook;}interfaceGridOptions {workbook:Workbook;}Live workbook schema adopted by the store and updated by document operations.API reference →GridOptions.data?: ColumnarData | undefinedinterfaceGridOptions {data?:ColumnarData|undefined;}interfaceGridOptions {data?:ColumnarData|undefined;}Eager column-major values loaded into workbook.activeSheet; use instead of datasource.API reference →function createSelectionStatus(host: HTMLElement, grid: Grid): ShellPiecefunctioncreateSelectionStatus(host:HTMLElement,grid:Grid,):ShellPiecefunctioncreateSelectionStatus(host:HTMLElement,grid:Grid,):ShellPiece<output role="status"> that follows the grid's selection and its values. Text nodes only; polite live region so screen readers announce changes without interrupting.API reference →const statusHost: HTMLDivElementconststatusHost:HTMLDivElementconststatusHost:HTMLDivElementDocument.createElement<"div">(tagName: "div", options?: ElementCreationOptions): HTMLDivElement (+2 overloads)Document.createElement<"div">(tagName: "div", options?: ElementCreationOptions): HTMLDivElement (+2 overloads)Document.createElement<"div">(tagName: "div", options?: ElementCreationOptions): HTMLDivElement (+2 overloads)In an HTML document, the document.createElement() method creates the HTML element specified by localName, or an HTMLUnknownElement if localName isn't recognized. MDN ReferenceChildNode.after(...nodes: (Node | string)[]): voidChildNode.after(...nodes: (Node | string)[]): voidChildNode.after(...nodes: (Node | string)[]): voidInserts nodes just after node, while replacing strings in nodes with equivalent Text nodes. Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated. MDN Referenceconst status: ShellPiececonststatus:ShellPiececonststatus:ShellPieceAPI reference →const grid: Gridconstgrid:Gridconstgrid:GridThe imperative core grid this controller owns.API reference →ShellPiece.destroy(): voidShellPiece.destroy(): voidShellPiece.destroy(): voidRuns immediately before a retained element is removed or replaced.API reference →interface AbortControllerinterfaceAbortControllerinterfaceAbortControllerThe AbortController interface represents a controller object that allows you to abort one or more Web requests as and when desired. MDN Reference An AbortController cancels one or more Web requests: pass its signal to a request, then call abort(). MDN ReferenceGrid.on<"selection">(evt: "selection", fn: (e: {
selection: Selection | null;
}) => void): () => voidGrid.on<"selection">(evt: "selection", fn: (e: {selection:Selection|null;}) =>void): () =>voidGrid.on<"selection">(evt: "selection", fn: (e: {selection:Selection|null;}) =>void): () =>voidlet pending: AbortController | nulllet pending:AbortController|nulllet pending:AbortController|nullAbortController.abort(reason?: any): void (+1 overload)AbortController.abort(reason?: any): void (+1 overload)AbortController.abort(reason?: any): void (+1 overload)The abort() method of the AbortController interface aborts an asynchronous operation before it has completed. MDN Referenceconst controller: AbortControllerconstcontroller:AbortControllerconstcontroller:AbortControllervar AbortController: new () => AbortControllervar AbortController:new () =>AbortControllervar AbortController:new () =>AbortControllerThe AbortController interface represents a controller object that allows you to abort one or more Web requests as and when desired. MDN Reference An AbortController cancels one or more Web requests: pass its signal to a request, then call abort(). MDN Referenceconst summary: SelectionSummary | nullconstsummary:SelectionSummary|nullconstsummary:SelectionSummary|nullGrid.summarizeSelection(signal?: AbortSignal): Promise<SelectionSummary | null>Grid.summarizeSelection(signal?: AbortSignal): Promise<SelectionSummary |null>Grid.summarizeSelection(signal?: AbortSignal): Promise<SelectionSummary |null>Totals for the current selection, for a status bar. Large selections are read in chunks between frames, so the page stays responsive; abort signal to stop early, which rejects with the signal's reason. Resolves null when nothing is selected.API reference →AbortController.signal: AbortSignalinterfaceAbortController {signal:AbortSignal;}interfaceAbortController {signal:AbortSignal;}The signal read-only property of the AbortController interface returns an AbortSignal object instance, which can be used to communicate with/abort an asynchronous operation as desired. MDN ReferenceAPI reference →const summary: SelectionSummaryconstsummary:SelectionSummaryconstsummary:SelectionSummarySelectionSummary.numericCount: numberinterfaceSelectionSummary {numericCount:number;}interfaceSelectionSummary {numericCount:number;}Cells that hold a number (dates are numbers too).var console: Consolevar console:Consolevar console:ConsoleConsole.log(...data: any[]): void (+1 overload)Console.log(...data: any[]): void (+1 overload)Console.log(...data: any[]): void (+1 overload)The console.log() static method outputs a message to the console. MDN ReferenceSelectionSummary.min: number | nullinterfaceSelectionSummary {min:number|null;}interfaceSelectionSummary {min:number|null;}SelectionSummary.max: number | nullinterfaceSelectionSummary {max:number|null;}interfaceSelectionSummary {max:number|null;}(local var) error: unknown(local var) error: unknown(local var) error: unknownAbortSignal.aborted: booleaninterfaceAbortSignal {aborted:boolean;}interfaceAbortSignal {aborted:boolean;}The aborted read-only property returns a value that indicates whether the asynchronous operations the signal is communicating with are aborted (true) or not (false). MDN Reference