Skip to content

ServerSidePlugin

Since v0.1.1

Server-Side Data Plugin for tbw-grid

Central data orchestrator for the grid. Manages fetch, cache, and row-model for server-side data loading. Structural plugins (Tree, GroupingRows) can claim data via events; the core grid uses it as flat rows when unclaimed.

import { ServerSidePlugin } from '@toolbox-web/grid/plugins/server-side';
interface ServerSideDataSource {
getRows(params: GetRowsParams): Promise<GetRowsResult>;
getChildRows?(params: GetChildRowsParams): Promise<GetChildRowsResult>;
}
OptionTypeDescription
pageSize?numberNumber of nodes requested per getRows() call. The same value is surfaced on params.pageSize inside the callback, so backends that expect an explicit page-size query parameter can forward it directly. Larger values reduce request count at the cost of longer per-request latency.
maxConcurrentRequests?numberMaximum number of concurrent getRows() requests. Limits how many blocks can be fetched simultaneously during fast scrolling. Set to 1 for strict sequential loading; higher values improve perceived performance.
loadThreshold?numberPrefetch slack in node count (rows). When > 0, blocks are loaded as soon as the user is within loadThreshold rows of an unloaded block, rather than only when the visible window enters it. This reduces the number of placeholder rows the user sees during gentle scrolling at the cost of slightly more eager fetching.
dataSource?ServerSideDataSource<unknown>Data source for server-side loading. When provided, the plugin auto-initializes on attach — no need to call setDataSource().
sortMode?server | localHow sort changes affect the cache. - 'server' (default): purge cache and refetch via getRows({ sortModel }). Use when the backend supports the requested sort shape natively. MultiSortPlugin does not re-sort the returned rows locally — the data source’s order (and its loading placeholders’ block positions) is shown as-is. - 'local': keep the loaded blocks; sort the loaded rows in-place via the active sort plugin (MultiSort or core sort). sortModel is not sent on subsequent block fetches. Loading placeholder rows (see isLoadingPlaceholder()) are pinned to the end regardless of direction.
filterMode?server | localHow filter changes affect the cache. - 'server' (default): purge cache and refetch via getRows({ filterModel }). FilteringPlugin does not re-filter the returned rows locally — the data source’s result (and its loading placeholders) is shown as-is. - 'local': keep the loaded blocks; filter only the rows currently in cache via FilteringPlugin’s normal pipeline. filterModel is not sent on subsequent block fetches. Loading placeholders (see isLoadingPlaceholder()) always pass the filter until their block loads.
placeholderRendering?columns | loading-rowHow rows whose block is still loading are rendered. - 'loading-row' (default): the grid renders each placeholder itself, as a full-width row in the core row-loading state (.tbw-row-loading, aria-busy="true", the .tbw-row-loading-overlay spinner). Column renderers, format, cellClass, rowClass and a Responsive cardRenderer are not called for it, and context menus (mouse or keyboard) do not open on it. - 'columns': placeholders take the normal cell render path, so your column renderers and callbacks receive them and can draw a custom loading look. Detect them with isLoadingPlaceholder().
import '@toolbox-web/grid';
import '@toolbox-web/grid/features/server-side';
grid.gridConfig = {
columns: [...],
features: {
serverSide: {
pageSize: 50,
dataSource: {
async getRows(params) {
const response = await fetch(
`/api/data?start=${params.startNode}&end=${params.endNode}`
);
const data = await response.json();
return { rows: data.rows, totalNodeCount: data.total };
},
},
},
},
};

Extends BaseGridPlugin

Inherited methods like attach(), detach(), afterRender(), etc. are documented in the base class.

Set the data source for server-side loading.

setDataSource(dataSource: ServerSideDataSource): void
NameTypeDescription
dataSourceServerSideDataSourceData source implementing the getRows method (and optionally getChildRows)

Refresh all data from the server. Purges cache and refetches from block 0.

refresh(): void

Clear all cached data without refreshing. The known total is kept so the grid keeps rendering placeholders; nothing is fetched until the next scroll.

purgeCache(): void

Get the total node count from the server.

getTotalNodeCount(): number

Check if a specific node is loaded in the cache.

isNodeLoaded(nodeIndex: number): boolean
NameTypeDescription
nodeIndexnumberNode index to check

Get the number of loaded cache blocks.

getLoadedBlockCount(): number