Skip to main content

@topgrid/grid-pro-serverside-core

Framework-neutral server-side row model core: block cache, SSRM controller, lazy-group tree cache, viewport row model, server pivot columns (no React/Vue; @tanstack/table-core type-only). · Commercial (EULA)

Auto-generated

This page is auto-generated from the TSDoc comments in the source code (internal markers stripped). For a curated getting-started summary, see the API Reference.

49 public exports — 27 functions · 0 hooks · 0 components · 22 types · 0 constants.

Functions

acceptBlock

Accept a block response. Rejected (state unchanged) if responseEpoch !== cache.epoch — the request was issued for a query that has since been invalidated. On accept, the block is stored as loaded; lastRow (when provided) sets the known total row count.

acceptBlock(cache: BlockCacheState<TData>, blockIndex: number, rows: TData[], responseEpoch: number, lastRow: number): BlockCacheState<TData>

acceptTreeBlock

Accept a child block — discarded unless (a) epoch === tree.epoch AND (b) the node still exists (the invariant). On accept, stores into that node's cache.

acceptTreeBlock(tree: TreeCacheState<TData>, pathKey: string, blockIndex: number, rows: TData[], epoch: number, lastRow: number): TreeCacheState<TData>

blockBounds

Half-open absolute row range [startRow, endRow) of a block.

blockBounds(blockIndex: number, blockSize: number): {}

blockIndexOf

Block index containing an absolute row index.

blockIndexOf(rowIndex: number, blockSize: number): number

buildServerPivotColumns

Build a nested pivot-result column tree from the server's flat field keys.

buildServerPivotColumns(fields: string[], separator: string): ServerPivotColumn[]
ParameterTypeDescription
fieldsstring[]server-generated pivot-result field keys (order = desired column order).
separatorstringsegment delimiter within a field key (default '|').

clearBlock

Drop an in-flight block so it can be re-requested — call on a failed getRows (the datasource contract says a rejected fetch leaves the block unloaded, re-requestable). No-op if the epoch has since changed (invalidate already cleared it) or the block is no longer loading, so a late failure can't disturb a fresh query.

clearBlock(cache: BlockCacheState<TData>, blockIndex: number, epoch: number): BlockCacheState<TData>

clearTreeBlock

Drop a failed in-flight child block so it can be re-requested (epoch + node-existence guarded).

clearTreeBlock(tree: TreeCacheState<TData>, pathKey: string, blockIndex: number, epoch: number): TreeCacheState<TData>

createBlockCache

Create an empty cache at epoch 0.

createBlockCache(blockSize: number): BlockCacheState<TData>

createServerSideController

createServerSideController(datasource: ServerSideDatasource<TData>, options: ServerSideControllerOptions, onChange: () =>): ServerSideController<TData>
ParameterTypeDescription
datasourceServerSideDatasource<TData>
optionsServerSideControllerOptions
onChange(…) => …called whenever the materialized data changes (a block resolved / invalidated). The hook wires this to setState. NOT called synchronously from ensureRange for an unchanged cache — so a scroll→render→onChange loop cannot form (materialize is range-independent; placeholders exist from construction).

createServerSideTreeController

createServerSideTreeController(datasource: ServerSideDatasource<TData>, options: ServerSideTreeControllerOptions, onChange: () =>): ServerSideTreeController<TData>

createTreeCache

createTreeCache(blockSize: number, rowGroupCols: string[]): TreeCacheState<TData>

createViewportRowModel

Create a viewport row-model controller. Calls datasource.init once with push callbacks, forwards visible ranges via setRange, and re-emits a materialized array whenever the datasource pushes a count or rows (including live in-place updates).

createViewportRowModel(datasource: ViewportDatasource<TData>, options: ViewportRowModelOptions, onChange: () =>): ViewportRowModel<TData>

ensureNode

Create the node for pathKey if missing, stamped with the current global epoch.

ensureNode(tree: TreeCacheState<TData>, pathKey: string): TreeCacheState<TData>

ensureVisibleNodes

Ensure every node referenced by the current display range exists (so its blocks can be planned).

ensureVisibleNodes(tree: TreeCacheState<TData>, displayStart: number, displayEnd: number): TreeCacheState<TData>

flattenTree

The full display list (group rows + children/placeholders), in render order. Feed to <Grid data>.

flattenTree(tree: TreeCacheState<TData>): TreeDisplayRow<TData>[]

invalidate

Invalidate the whole cache (AC④) — clears all blocks and bumps the epoch so any in-flight response (old epoch) is later rejected by acceptBlock. Called on sort/filter/group change or explicit refresh. rowCount is cleared (the new query may have a different total).

invalidate(cache: BlockCacheState<TData>): BlockCacheState<TData>

invalidateTree

Invalidate the whole tree (sort/filter/grouping change) — bump the global epoch and drop every node's blocks; expanded is kept (re-fetched). Any in-flight response (old epoch) is rejected.

invalidateTree(tree: TreeCacheState<TData>): TreeCacheState<TData>

isExpanded

isExpanded(tree: TreeCacheState<TData>, groupKeys: readonly string[]): boolean

isRowPlaceholder

Type guard for placeholder rows from materialize.

isRowPlaceholder(row: unknown): row

markLoading

Mark a block in-flight at the current epoch (the request's captured epoch is cache.epoch).

markLoading(cache: BlockCacheState<TData>, blockIndex: number): BlockCacheState<TData>

markTreeLoading

Mark a node's block in-flight at the current global epoch (node must exist).

markTreeLoading(tree: TreeCacheState<TData>, pathKey: string, blockIndex: number): TreeCacheState<TData>

materialize

Materialize a totalCount-length array (AC④ memory note): loaded indices carry their real row, not-yet-loaded indices carry a RowPlaceholder. Pure — feeds the existing <Grid enableVirtualization data> ( shape: minimal primitive on host public surface).

materialize(cache: BlockCacheState<TData>, totalCount: number): TData | RowPlaceholder[]

materializeViewport

Pure: build a placeholder-filled array of length rowCount from a sparse index → row map. Not-yet-pushed indices carry a RowPlaceholder (same shape as the SSRM materialize).

materializeViewport(rows: Map<number, TData>, rowCount: number): RowPlaceholder | TData[]

pathKeyOf

Stable key for a group path. Root = pathKeyOf([]) === "[]".

pathKeyOf(groupKeys: readonly string[]): string

planBlocks

Block indices a visible row range needs that are not already loaded or in-flight (AC① — one request per block). visibleStartRow/visibleEndRow are inclusive row indices. Returns ascending, de-duplicated, missing-only block indices.

planBlocks(cache: BlockCacheState<TData>, visibleStartRow: number, visibleEndRow: number): number[]

planTreeBlocks

Plan the missing blocks for a visible display range (one request per node-block). Maps the display range to per-node local ranges, then reuses planBlocks per node (dedup of loaded/in-flight). Nodes must be ensured first (ensureVisibleNodes).

planTreeBlocks(tree: TreeCacheState<TData>, displayStart: number, displayEnd: number): TreeBlockRequest[]

toggleGroup

Expand or collapse a group. Expand adds the path to expanded and ensures its node exists. Collapse removes it from expanded and purges its node + all descendant nodes (so any in-flight child response for them is later rejected by acceptTreeBlock's node-existence check).

toggleGroup(tree: TreeCacheState<TData>, groupKeys: readonly string[]): TreeCacheState<TData>

Types & Interfaces

BlockCacheState

Pure block-cache value. Transitions are pure functions in ./internal/blockCache that return a new state (never mutate). epoch is the query generation — bumped on sort/filter/group change so stale in-flight responses are rejected (the SSRM invariant).

PropertyTypeDescription
blocksMap<number, BlockState<TData>>blockIndex → state.
blockSizenumberRows per block (fixed).
epochnumberQuery generation. Responses tagged with a stale epoch are discarded.
rowCountnull | numberKnown total row count (from lastRow), else null.

BlockState

Internal per-block state (rows present only when loaded).

PropertyTypeDescription
rows?TData[]
statusBlockStatus

GetRowsRequest

A block request: half-open row range [startRow, endRow) + current sort/filter.

For lazy grouping the request also carries the group path being expanded. groupKeys/ rowGroupCols are optional — absent/empty = flat mode (/ behavior unchanged), so existing flat datasources keep working. The level is groupKeys.length; the returned block holds group rows when level < rowGroupCols.length, otherwise leaf rows (AG convention).

PropertyTypeDescription
endRownumberOne past the last row index (exclusive).
filterModelFilterModelActive filter model (server applies).
groupKeys?string[]Path of group key values to the node whose children are requested ([]/absent = top level).
pivotCols?string[]Pivot dimension columns (outermost first) — the values become column groups.
pivotMode?booleanServer-side pivot — optional, absent = no pivot (flat/group behavior unchanged). When pivotMode is true the server pivots valueCols across pivotCols and returns rows keyed by the generated pivot-result fields, plus the field list in GetRowsResult.pivotResultFields.
rowGroupCols?string[]Columns being grouped, outermost first (absent/empty = no grouping).
sortModelSortModelItem[]Active sort directives (server applies).
startRownumberFirst row index (inclusive) — within the addressed group's children.
valueCols?string[]Value/measure columns aggregated within each pivot column combination.

GetRowsResult

A block response. lastRow carries the total/last-row signal the virtualizer needs to size the scroll area: set it to the absolute total row count once the server knows the end has been reached (e.g. a partial final block), otherwise leave undefined (more rows exist).

PropertyTypeDescription
lastRow?numberAbsolute total row count when known (end reached), else undefined.
pivotResultFields?string[]Server-side pivot — the generated pivot-result field keys (e.g. "East|sales"), in column order. The grid feeds these to buildServerPivotColumns to derive the dynamic column tree. Absent for non-pivot responses. (Typically identical across blocks of one query.)
rowsTData[]The rows for the requested range (length ≤ endRow − startRow).

RowPlaceholder

Placeholder row emitted by materialize for not-yet-loaded indices.

PropertyTypeDescription
__ssrmPlaceholdertrueDiscriminant — consumers test this to render a loading skeleton cell.
rowIndexnumberAbsolute row index this placeholder stands in for.

ServerPivotColumn

A derived pivot-result column: a leaf (accessorKey) or a group (columns).

PropertyTypeDescription
accessorKey?stringLeaf only: the row field this column reads (the full server field key).
columns?ServerPivotColumn[]Group only: nested child columns.
headerstringHeader label (the dimension value, or the measure name for a leaf).
idstringStable id (group: the path prefix; leaf: the full field key).

ServerSideController

PropertyTypeDescription
ensureRangeunknown
getDataunknown
getTotalCountunknown
refreshunknown
setColumnFiltersunknown
setSortingunknown

ServerSideControllerOptions

PropertyTypeDescription
blockSizenumber
pivot?{ … }Server-side pivot — optional. Absent = flat/group request unchanged.
rowCountnumber

ServerSideDatasource

Consumer-supplied datasource. The single seam between the grid and the server.

PropertyTypeDescription
getRowsunknown

ServerSideTreeController

PropertyTypeDescription
ensureRangeunknown
getDataunknown
refreshunknown
setColumnFiltersunknown
setSortingunknown
toggleGroupunknown

ServerSideTreeControllerOptions

PropertyTypeDescription
blockSizenumber
rowGroupColsstring[]Grouping columns, outermost first.

SortModelItem

One server sort directive (column + direction). Mirrors TanStack SortingState item.

PropertyTypeDescription
colIdstringColumn id.
sort"asc" | "desc"Sort direction.

SsrmRowMeta

Per-display-row metadata attached as __ssrm by the tree flatten. Consumers read it in a cell renderer to draw the group toggle + indent, and pass groupKeys to toggleGroup.

PropertyTypeDescription
expanded?booleanGroup rows only: whether currently expanded.
groupbooleanTrue for a group row, false for a leaf row.
groupKeysstring[]Group rows: path including this group's own key (the toggleGroup target). Leaf rows: parent path.
levelnumberDepth (0 = outermost group level).

TreeBlockRequest

A block to fetch: which node (groupKeys/pathKey) and which block index within it.

PropertyTypeDescription
blockIndexnumber
groupKeysstring[]
pathKeystring

TreeCacheState

Hierarchical cache : a flat Map<pathKey, BlockCacheState> keyed by JSON.stringify(groupKeys) — each node owns a block cache for its children. epoch is global across the whole tree (sort/filter/grouping change bumps it → every node's responses invalidate). expanded is the set of expanded path keys; collapsing purges the node.

PropertyTypeDescription
blockSizenumber
epochnumberGlobal query generation — responses tagged with a stale epoch are discarded.
expandedSet<string>Expanded path keys (root "[]" is always conceptually expanded).
nodesMap<string, BlockCacheState<TData>>pathKey (JSON.stringify(groupKeys)) → that node's children block cache.
rowGroupColsstring[]Grouping columns, outermost first. Level depth = rowGroupCols.length.

ViewportDatasource

Consumer-supplied viewport datasource (AG IViewportDatasource shape).

PropertyTypeDescription
destroy?unknown
initunknown
setViewportRangeunknown

ViewportDatasourceParams

Callbacks the controller hands the datasource so it can push counts/rows.

PropertyTypeDescription
setRowCount(…) => …Set the total row count (sizes the virtualizer).
setRowData(…) => …Push rows by absolute index (in-place — re-pushing an index updates that row live).

ViewportRowModel

PropertyTypeDescription
destroyunknown
getDataunknown
getRowCountunknown
setRangeunknown

ViewportRowModelOptions

PropertyTypeDescription
rowCountnumberInitial total row count (refined by the datasource's setRowCount).

BlockStatus

Internal per-block status.

type BlockStatus = "loading" | "loaded"

FilterModel

Opaque per-column filter map. The datasource interprets it; the grid never inspects it (keeps filtering server-defined). Shape is consumer/server contract.

type FilterModel = Record<string, unknown>

TreeDisplayRow

A display-list row: the data (or placeholder) plus __ssrm meta. Fed to <Grid data>.

type TreeDisplayRow = TData | RowPlaceholder & {}