Skip to content

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.

import { ServerSidePlugin } from '@toolbox-web/grid/plugins/server-side';
OptionTypeDefaultDescription
pageSizenumber100Rows per block
cacheBlockSizenumberpageSizeCache block size
maxConcurrentRequestsnumber2Max parallel data requests
interface ServerSideDataSource {
getRows(params: GetRowsParams): Promise<GetRowsResult>;
}
MethodSignatureDescription
setDataSource(ds: ServerSideDataSource) => voidSet the data source
refresh() => voidRefresh current data
clearCache() => voidClear all cached blocks
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));

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

Refresh all data from the server.

refresh(): void

Clear all cached data without refreshing.

purgeCache(): void

Get the total row count from the server.

getTotalRowCount(): number

Check if a specific row is loaded in the cache.

isRowLoaded(rowIndex: number): boolean
NameTypeDescription
rowIndexnumberRow index to check

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