ServerSidePlugin
Server-Side Data Plugin for tbw-grid
Enables lazy loading of data from a remote server with caching and block-based fetching. Ideal for large datasets where loading all data upfront is impractical.
Installation
Section titled “Installation”import { ServerSidePlugin } from '@toolbox-web/grid/plugins/server-side';Configuration Options
Section titled “Configuration Options”| Option | Type | Default | Description |
|---|---|---|---|
pageSize | number | 100 | Rows per block |
cacheBlockSize | number | pageSize | Cache block size |
maxConcurrentRequests | number | 2 | Max parallel data requests |
DataSource Interface
Section titled “DataSource Interface”interface ServerSideDataSource { getRows(params: GetRowsParams): Promise<GetRowsResult>;}Programmatic API
Section titled “Programmatic API”| Method | Signature | Description |
|---|---|---|
setDataSource | (ds: ServerSideDataSource) => void | Set the data source |
refresh | () => void | Refresh current data |
clearCache | () => void | Clear all cached blocks |
Example
Section titled “Example”Basic Server-Side Loading
Section titled “Basic Server-Side Loading”import '@toolbox-web/grid';import { ServerSidePlugin } from '@toolbox-web/grid/plugins/server-side';
const dataSource = { async getRows(params) { const response = await fetch( `/api/data?start=${params.startRow}&end=${params.endRow}` ); const data = await response.json(); return { rows: data.rows, totalRowCount: data.total }; },};
const plugin = new ServerSidePlugin({ pageSize: 50 });grid.gridConfig = { columns: [...], plugins: [plugin],};
grid.ready().then(() => plugin.setDataSource(dataSource));See Also
Section titled “See Also”ServerSideConfigfor configuration optionsServerSideDataSourcefor data source interface
Extends BaseGridPlugin
Inherited methods like
attach(),detach(),afterRender(), etc. are documented in the base class.
Methods
Section titled “Methods”setDataSource()
Section titled “setDataSource()”Set the data source for server-side loading.
setDataSource(dataSource: ServerSideDataSource): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
dataSource | ServerSideDataSource | Data source implementing the getRows method |
refresh()
Section titled “refresh()”Refresh all data from the server.
refresh(): voidpurgeCache()
Section titled “purgeCache()”Clear all cached data without refreshing.
purgeCache(): voidgetTotalRowCount()
Section titled “getTotalRowCount()”Get the total row count from the server.
getTotalRowCount(): numberisRowLoaded()
Section titled “isRowLoaded()”Check if a specific row is loaded in the cache.
isRowLoaded(rowIndex: number): booleanParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
rowIndex | number | Row index to check |
getLoadedBlockCount()
Section titled “getLoadedBlockCount()”Get the number of loaded cache blocks.
getLoadedBlockCount(): number
AI assistants: For complete API documentation, implementation guides, and code examples for this library, see https://raw.githubusercontent.com/OysteinAmundsen/toolbox/main/llms-full.txt