Skip to content

GridApi

All methods live on the Grid<T> instance (GridApi<T> extends HierarchyApi<T>). Calling mutating or query methods after destroy() throws an explicit destroyed-grid error.

  • setRowData(rowData: readonly T[]): void — Replaces client row data, creates a new dataEpoch, and emits modelUpdated and stateChanged.
  • setRowSource(rowSource: RowSource<T>): void — Attaches a synchronous lazy/direct RowSource<T>, replaces the active source, and emits modelUpdated.
  • applyRowTransaction(transaction: Readonly<RowDataTransaction<T>>): Readonly<RowTransactionResult> — Atomically adds, updates, or removes rows by rowId and emits rowDataChanged and modelUpdated. Throws if row identity is not configured or an update targets a missing/duplicate ID.
  • applyRowTransactionAsync(transaction: Readonly<RowDataTransaction<T>>): Promise<Readonly<AsyncRowTransactionResult>> — Queues a row transaction for the next animation-frame batch; resolves with { status: 'applied' | 'unchanged', ... } or { status: 'cancelled', reason } on dataEpochChanged or destroy.
  • flushAsyncTransactions(): Promise<Readonly<AsyncRowTransactionResult> | null> — Immediately commits pending queued async transactions or returns null if the queue is empty.
  • refreshRows(): void — Marks the current row view dirty and schedules a re-read/re-render without resetting state.
  • getRowAddress(displayIndex: number): Readonly<RealRowAddress> | null — Resolves a visible display index to its stable RealRowAddress (or null if out of bounds or synthetic/unloaded).
  • setColumnDefs(columnDefs: readonly ColumnDef<T>[], options?: Readonly<ColumnDefinitionsUpdate<T>>): void — Atomically replaces column definitions, matching kept columns by colId. Rejects if a removed column is referenced by active grouping, cell spans, or checkboxColId, or if columns/order change while pivot is active. Emits columnStateChanged and stateChanged.
  • getColumnState(): Readonly<ColumnState> — Returns a serializable version: 1 snapshot of column widths, visibility, pinning, flex, and order.
  • applyColumnState(state: Readonly<ColumnState>): void — Atomically applies a full ColumnState snapshot and emits columnStateChanged and stateChanged.
  • applyColumnStatePatch(patch: Readonly<ColumnStatePatch>): void — Applies partial column updates (columns, optional applyOrder) and emits columnStateChanged and stateChanged.
  • resetColumnState(): void — Restores column widths, visibility, pinning, flex, and order back to the current columnDefs defaults.
  • setColumnWidth(colId: string, width: number): void — Sets an explicit pixel width on a column and emits columnStateChanged.
  • setColumnVisibility(colId: string, isVisible: boolean): void — Shows or hides a column and emits columnStateChanged.
  • moveColumn(colId: string, targetIndex: number): void — Moves a column to targetIndex within its pin zone and emits columnStateChanged.
  • setColumnPinned(colId: string, pinned: ColumnPin): void — Pins ('start' | 'end') or unpins (null) a column and emits columnStateChanged.
  • setColumnFlex(colId: string, flex: number | null): void — Updates or clears proportional flex sizing on a column and emits columnStateChanged.
  • sizeColumnsToFit(colIds?: readonly string[]): void — Scales center columns (or colIds) to fill available center viewport width.
  • autoSizeColumns(colIds: readonly string[]): void — Measures rendered/sampled cell text widths for colIds and updates widths within minWidth/maxWidth.
  • getSortModel(): SortModel — Returns the active SortModel (readonly SortModelItem[]).
  • setSortModel(model: SortModel): void — Replaces the active sort model and emits sortChanged, modelUpdated, and stateChanged.
  • getFilterModel(): FilterModel — Returns the active column filter map keyed by colId.
  • setFilterModel(model: FilterModel): void — Replaces active column filters and emits filterChanged, modelUpdated, and stateChanged.
  • setQuickFilter(value: string): void — Updates the global quick filter string and emits filterChanged and modelUpdated.
  • getPaginationState(): Readonly<PaginationState> — Returns { enabled, page, pageSize }.
  • setPaginationState(state: Readonly<PaginationState>): void — Updates pagination configuration/page index (clamping to valid pages) and emits paginationChanged and stateChanged.
  • getSelectionState(): Readonly<SelectionState | SelectionStateV3> — Returns the current row and cell range selection snapshot (SelectionStateV3 when pivot mode is active).
  • applySelectionState(state: Readonly<SelectionState | SelectionStateV3>): void — Restores a serialized selection snapshot and emits selectionChanged and stateChanged.
  • setRowSelected(row: Readonly<RowAddress>, selected: boolean): boolean — Selects or deselects a row by RowAddress; returns false if not found/ineligible. Emits selectionChanged.
  • isRowSelected(row: Readonly<RowAddress>): boolean — Returns true if the target row is currently selected.
  • selectAllRows(scope?: 'filtered' | 'page' | 'all'): void — Selects all eligible rows in 'filtered' (default), 'page', or 'all' scope and emits selectionChanged.
  • clearRowSelection(): void — Clears all selected rows and emits selectionChanged.
  • setCellRange(anchor: Readonly<DisplayCellAddress>, focus: Readonly<DisplayCellAddress>, add?: boolean): boolean — Sets (or appends when add is true) a rectangular cell range; returns false if rejected. Emits selectionChanged.
  • clearCellSelection(): void — Clears all cell ranges and emits selectionChanged.
  • clearSelection(): void — Clears both row and cell range selections atomically.
  • getFocusPosition(): Readonly<FocusPosition> — Returns the current logical focus target (cell, header, fullWidth, region, pivotResult, or null).
  • setFocusedCell(cell: Readonly<CellAddress> | null, options?: Readonly<FocusOptions>): boolean — Moves logical focus to a body cell (or clears with null); returns false if non-focusable. Emits focusChanged.
  • setFocusedHeader(colId: string, options?: Readonly<FocusOptions>): boolean — Moves logical focus to a column header; returns false if hidden/missing.
  • setFocusedFullWidthRow(row: Readonly<DisplayNodeOrRowAddress>, options?: Readonly<FocusOptions>): boolean — Moves logical focus to a full-width row.
  • setFocusedRegionCell(address: Readonly<RegionRowAddress | RegionTotalAddress>, colId: string, options?: Readonly<FocusOptions>): boolean — Moves logical focus to a pinned top/bottom row or pinned total cell.
  • setFocusedDisplayCell(cell: Readonly<DisplayCellAddress> | null, options?: Readonly<FocusOptions>): boolean — Moves logical focus to a hierarchy/display node cell.
  • setFocusedPivotCell(cell: Readonly<PivotResultCellAddress> | null, options?: Readonly<FocusOptions>): boolean — Moves logical focus to a pivot result cell.
  • ensureRowVisible(row: Readonly<RowAddress>, alignment?: ScrollAlignment): boolean — Scrolls vertically to reveal row.
  • ensureColumnVisible(colId: string, alignment?: ScrollAlignment): boolean — Scrolls horizontally to reveal colId.
  • ensureCellVisible(cell: Readonly<CellAddress>, alignment?: ScrollAlignment): boolean — Scrolls both axes to reveal cell.
  • ensureDisplayNodeVisible(address: Readonly<DisplayNodeAddress>, alignment?: ScrollAlignment): boolean — Scrolls vertically to reveal a hierarchy display node.
  • ensureRegionCellVisible(address: Readonly<RegionRowAddress | RegionTotalAddress>, colId: string): boolean — Scrolls horizontally to reveal a pinned region cell.
  • ensurePivotCellVisible(cell: Readonly<PivotResultCellAddress>): boolean — Scrolls to reveal a pivot result cell.
  • startEditing(cell: Readonly<CellAddress>): boolean — Opens an editor on cell; returns false if not editable. Emits editSessionChanged.
  • getEditSession(): Readonly<EditSession> | null — Returns the active edit session metadata or null.
  • commitEditing(newValue: unknown): Readonly<CellMutationResult> | null — Validates and commits newValue (or emits cellEditRequest for remote/lazy sources); returns null if no session is active.
  • cancelEditing(): boolean — Discards the active edit session without mutating data; returns false if none is active.
  • applyCellChanges(changes: readonly Readonly<CellValueChange>[], options?: Readonly<CellMutationOptions>): Readonly<CellMutationResult> — Runs the full value mutation pipeline over programmatic cell updates; emits cellValuesChanged or cellEditRequest.
  • fillCells(source: Readonly<FillRange>, target: Readonly<FillRange>): Readonly<CellMutationResult> | null — Programmatically fills target cells from source.
  • getHistoryState(): Readonly<HistoryState> — Returns { enabled, undoCount, redoCount, retainedRows, retainedCells, version }.
  • canUndo(): boolean / canRedo(): boolean — Returns whether an undo or redo step is available.
  • undo(): Readonly<HistoryResult> / redo(): Readonly<HistoryResult> — Reverts or reapplies the last recorded edit/clipboard/fill batch and emits historyChanged and cellValuesChanged.
  • clearHistory(): boolean — Clears the undo/redo stack; returns false if history is disabled.
  • getClipboardText(options?: Readonly<ClipboardCopyOptions>): string | null — Builds quoted TSV text for the current selection/focus (ClipboardModule required on next-grid-js/core). Returns null if clipboard is disabled or unavailable.
  • copyToClipboard(options?: Readonly<ClipboardCopyOptions>): Promise<string | null> — Writes selected/focused TSV to the system clipboard (ClipboardModule required on ./core).
  • cutToClipboard(options?: Readonly<ClipboardCopyOptions>): Promise<Readonly<CellMutationResult> | null> — Copies and clears editable cells (ClipboardModule required on ./core).
  • pasteFromText(text: string): Readonly<CellMutationResult> | null — Decodes TSV text and applies edits starting at selection/focus (ClipboardModule required on ./core).
  • pasteFromClipboard(): Promise<Readonly<CellMutationResult> | null> — Reads the system clipboard and pastes into the grid (ClipboardModule required on ./core).
  • deleteSelectedCells(): Readonly<CellMutationResult> | null — Clears editable selected/focused cells (ClipboardModule required on ./core).
  • getDisplayedRowNode(index: number): Readonly<DisplayNode<T>> | undefined — Returns the DisplayNode<T> at display index.
  • getGroupingState(): Readonly<HierarchyState> — Returns the serialized hierarchy mode, columns, aggregations, and expansion state.
  • getHierarchyCounts(): Readonly<HierarchyCounts> | null — Returns { sourceRows, eligibleRows, loadedDataRows, visibleNodes, pageNodes, displayExtent } or null when flat.
  • setRowGrouping(options: Readonly<RowGroupingOptions<T>> | false): void — Enables, updates, or disables column-based row grouping; emits hierarchyChanged and stateChanged.
  • setHierarchyOptions(options: Readonly<HierarchyOptions<T>> | false): void — Atomically replaces grouping or tree options, aggregations, and totals.
  • setGroupExpanded(address: Readonly<DisplayNodeAddress>, expanded: boolean): boolean — Expands or collapses a group/tree node by address.
  • expandAllGroups(): boolean / collapseAllGroups(): boolean — Expands or collapses all client hierarchy branches.
  • setHierarchyMetadataLimit(limit: number): boolean — Sets maxHierarchyMetadataEntries cap for server-side grouping metadata.
  • setPivot(options: false | Readonly<PivotOptions>): void — Enables, updates, or disables pivot mode and emits pivotChanged and stateChanged.
  • getPivotState(): Readonly<PivotState> — Returns current pivot configuration and expansion state.
  • setPivotColumnLimit(limit: number): boolean — Adjusts maximum generated pivot columns (1..4096).
  • getDisplayedPivotNode(index: number): Readonly<PivotResultNode> | undefined — Returns the rendered pivot node at index.
  • getPivotCounts(): Readonly<PivotCounts> | null — Returns client pivot row/column counts or null.
  • getServerPivotCounts(): Readonly<ServerPivotCounts> | null — Returns server pivot counts or null.
  • getPivotRequestState(): Readonly<PivotRequestState> — Returns server pivot request status and error info.
  • setPivotGroupExpanded(row: Readonly<PivotResultRowAddress>, expanded: boolean): boolean — Expands or collapses a pivot row group.
  • setPivotCellRange(anchor: Readonly<PivotResultCellAddress>, focus: Readonly<PivotResultCellAddress>, add?: boolean): boolean — Selects a rectangular range of pivot result cells.
  • setDetailExpanded(row: Readonly<DisplayNodeOrRowAddress>, expanded: boolean): boolean — Expands or collapses a Master/Detail row; emits detailChanged.
  • getDetailState(): Readonly<DetailState> — Returns currently expanded detail row addresses.
  • setPinnedRows(region: PinnedRowRegion, rows: readonly Readonly<PinnedRow<T>>[]): void — Replaces 'top' or 'bottom' supplied pinned rows; emits pinnedRowsChanged.
  • getPinnedRows(region: PinnedRowRegion): readonly Readonly<PinnedRow<T>>[] — Returns supplied pinned rows for 'top' or 'bottom'.
  • clearPinnedRows(): void — Removes all supplied pinned rows from both regions.
  • setPinnedTotals(options: false | Readonly<PinnedTotalsOptions>): void — Configures or disables projected pinned totals; emits pinnedRowsChanged.
  • setCellSpans(spans: readonly Readonly<CellSpan>[]): void — Replaces rectangular cell spans atomically; emits cellSpansChanged.
  • getCellSpanState(): Readonly<CellSpanState> — Returns active and suppressed cell spans.
  • resetRowHeights(addresses?: readonly RowHeightAddress[]): void — Invalidates cached measured row heights (all or specific addresses) and re-measures.
  • getDatasourceState(): Readonly<DatasourceState> | null — Returns live block cache / viewport connection telemetry or null for client sources.
  • setRemoteDatasource(datasource: RemoteDatasource<T>): void — Replaces the attached RemoteDatasource<T> for 'infinite' / 'serverSide' models and clears cached blocks.
  • setViewportDatasource(datasource: ViewportDatasource<T>): void — Replaces the attached ViewportDatasource<T> for 'viewport' models.
  • setDatasourceContext(context: unknown): void — Updates opaque context passed to remote/viewport queries and refreshes data.
  • retryFailedRows(): void — Retries failed remote blocks or failed child hierarchy requests.
  • exportData<F extends DataExportFormat>(request: Readonly<DataExportRequest & { readonly format: F }>): Promise<Readonly<DataExportResultFor<F>>> — Builds CSV, JSON, Markdown (text), or Excel (bytes: Uint8Array) asynchronously in chunks (ExportModule required on next-grid-js/core). Supports signal?: AbortSignal.
  • downloadExport<F extends DataExportFormat>(request: Readonly<DataExportRequest & { readonly format: F }>): Promise<Readonly<DataExportResultFor<F>>> — Builds the export and triggers a browser file download (ExportModule required on ./core).
  • getTheme(): GridTheme — Returns the configured theme option ('auto' | 'light' | 'dark').
  • setTheme(theme: GridTheme): void — Switches the active color theme at runtime without recreating the grid or resetting scroll/selection.
  • getState(): Readonly<GridState> — Returns the complete JSON-serializable version: 5 state snapshot.
  • applyState(state: Readonly<GridStatePatch>): void — Atomically restores a version: 1..5 state snapshot or partial patch and emits stateChanged.
  • addEventListener<K extends GridEventType>(type: K, listener: GridEventListener<K>): void — Subscribes a typed listener to any GridEventMap event.
  • removeEventListener<K extends GridEventType>(type: K, listener: GridEventListener<K>): void — Unsubscribes a previously registered listener.
  • destroy(): void — Tears down DOM pools, observers, nested detail grids, modules, and listeners cleanly.