Server-side Row Grouping
Server-side row grouping for large datasets lets RevoGrid render grouped data from a backend route API. The browser keeps only visible grouped blocks and cached route blocks, while your server owns grouping, sorting, filtering, quick filtering, counts, and aggregates.
Use it for ERP, financial analytics, logs, operations, and reporting tools where a complete client-side dataset is too large.
- Group by one or multiple columns.
- Lazy-load group children on expand.
- Works with server-side Infinity Scroll semantics.
- Supports unknown row counts.
- Keeps browser memory low with block caching.
- Sends sort, filter, quick-filter, and group state to your backend.
import { ServerSideGroupingPlugin } from '@revolist/revogrid-pro';
const grid = document.createElement('revo-grid');
grid.serverSideGrouping = { groupBy: ['country', 'sport'], query: { refetchInterval: 5_000 }, // Optional native polling. loadRows: async (request, signal) => { const response = await fetch('/api/grid/grouping', { method: 'POST', signal, headers: { 'content-type': 'application/json' }, body: JSON.stringify(request), }); return response.json(); },};
grid.plugins = [ServerSideGroupingPlugin];The second signal argument is an optional cancellation signal. Forward it to
fetch so the transport can stop when its shared read is no longer needed; see
loader cancellation.
The optional refetchInterval
sets how often retained routes refresh automatically.
groupBy and loadRows are the only required options. The full configuration can add request tuning, a quick-filter payload, an imperative plugin controller, and an optimized expand-all datasource:
let groupingPluginControllerApi;
grid.serverSideGrouping = { groupBy: ['country', 'sport'], blockSize: 100, purgeClosedGroups: false, maxConcurrentRequests: 4, blockLoadDebounceMs: 25, quickFilter: { text: '' }, api: (api) => { groupingPluginControllerApi = api; }, loadRows, loadExpandedGroups: async (request, signal) => { const response = await fetch('/api/grid/grouping/expand-all', { method: 'POST', signal, headers: { 'content-type': 'application/json' }, body: JSON.stringify(request), }); return response.json(); },};The second signal argument is an optional cancellation signal. Forward it to
fetch so the transport can stop when its shared read is no longer needed; see
loader cancellation.
api is not a server endpoint. It is a callback that gives the application an imperative controller after the plugin is initialized. Use it from toolbar buttons, route changes, or refresh actions:
groupingPluginControllerApi?.refreshServerSide();groupingPluginControllerApi?.expandGroup(['Germany']);groupingPluginControllerApi?.purgeServerSideCache();loadRows is the required server datasource. It loads one route block at a time: root groups, child groups, or final leaf rows. loadExpandedGroups is optional and only optimizes expandAllGroups() by letting the backend return a flattened group tree in one request.
When AdvanceFilterPlugin is active, assigning grid.quickFilter refreshes the grouped datasource and forwards normalized { text, columns? } data in every request. An explicitly assigned grid-level quick filter takes precedence over serverSideGrouping.quickFilter, including an explicit empty value used to clear search. The config value remains the fallback until the grid-level property is assigned.
The plugin owns the main row source while active. InfinityScrollPlugin is complementary in behavior and request shape, but should not also own the same rgRow source. If both plugins are registered and serverSideGrouping is configured, Infinity Scroll no-ops with a warning.
When combining server-side grouping with selection filters, provide filter.selection.getItems from the same backing datasource used by your server loader. The grid source contains generated group rows and only the currently loaded route blocks, so deriving selection options from the visible grid source can produce incomplete values such as only Empty.
Request Contract
Section titled “Request Contract”loadRows(request, signal) receives the request below and an optional
cancellation signal:
{ route: ['Germany'], level: 1, groupBy: ['country', 'sport'], start: 0, limit: 100, sort: { revenue: 'desc' }, filter: { country: { type: 'contains', value: 'Ger' } }, quickFilter: { text: 'premium' }, parent: { key: 'Germany', count: 12450 }, levelParams: { tenantId: 'acme' }}Return group rows before the final grouping level:
{ groups: [ { key: 'Swimming', count: 2100, aggregates: { Revenue: 'EUR 9.2M' } }, { key: 'Cycling', count: 1540 } ], rowCount: 2, grandTotals: { Revenue: 'EUR 18.7M' }}Return leaf rows at the final level:
{ rows: [ { id: 1, country: 'Germany', sport: 'Swimming', city: 'Berlin', revenue: 1200 } ], rowCount: 2100, hasMore: true}When rowCount is omitted, RevoGrid treats the count as unknown and keeps a loading tail while hasMore is true.
Aggregates in value columns
Section titled “Aggregates in value columns”Set aggregateDisplay: 'columns' to show each server aggregate under its matching
column, alongside the group label and count. Aggregate keys must match column
prop values, rather than display names:
grid.columns = [ { prop: 'country', name: 'Country', size: 240 }, { prop: 'revenue', name: 'Revenue', size: 150 },];grid.serverSideGrouping = { groupBy: ['country'], aggregateDisplay: 'columns', formatAggregate: (prop, value) => (value == null ? '' : String(value)), loadRows: async (request) => { // Your backend computes aggregates across the complete filtered group. const response = await fetch('/api/grouped-rows', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(request), }); return response.json(); // Root response: { groups: [{ key: 'Germany', count: 1000, // aggregates: { revenue: 9200000 } }], rowCount: 1 } },};totals is a fallback when aggregates is omitted. Zero is displayed as 0;
missing or null values are blank unless formatAggregate supplies text. Values
remain available on the synthetic row model; the active grouping property and
internal group metadata retain their group identity. The formatter receives the
original server group, including its aggregate values.
The server owns calculations across unloaded rows. Expansion and collapse do not
recalculate totals from cached children. Column mode takes precedence over
groupRowRenderer. The default aggregateDisplay: 'label' retains the existing
full-row label and inline aggregate summary.
Runtime API
Section titled “Runtime API”The API is exposed through the config callback, not by mutating the grid instance.
grid.serverSideGrouping = { groupBy: ['country'], loadRows, api: (api) => { groupingPluginControllerApi = api; groupingPluginControllerApi?.expandGroup(['Germany']); groupingPluginControllerApi?.expandAllGroups(); groupingPluginControllerApi?.refreshRoute(['Germany']); groupingPluginControllerApi?.purgeServerSideCache(); console.log(groupingPluginControllerApi?.getServerSideCacheState()); },};Available methods:
| Method | Description |
|---|---|
expandGroup(id) | Expands and lazy-loads a group route. |
expandAllGroups() | Loads group blocks recursively and expands every server group route. Leaf-row blocks still load from the viewport. |
collapseGroup(id) | Collapses a group route. |
collapseAllGroups() | Collapses all group routes currently known by the cache. |
refreshServerSide() | Invalidates all route blocks and reloads root. |
refreshRoute(route) | Invalidates only one route branch when possible. |
purgeServerSideCache(route?) | Clears all cache or one route branch. |
getServerSideCacheState() | Returns debug route, block, loading, and queue state. |
expandAllGroups() opens every group route. It does not load every leaf row, so large final groups stay virtualized and fetch visible row blocks through the normal server-side scroll path.
When loadExpandedGroups is configured, expandAllGroups() uses that single endpoint instead of recursively loading route blocks:
grid.serverSideGrouping = { groupBy: ['country', 'sport'], loadRows, loadExpandedGroups: async (request) => ({ groups: [ { route: ['Germany'], key: 'Germany', count: 12450 }, { route: ['Germany', 'Swimming'], key: 'Swimming', count: 2100 }, { route: ['Germany', 'Cycling'], key: 'Cycling', count: 1540 }, ], }),};Each returned group row must include its full route. The plugin rebuilds group route blocks from this flattened tree and keeps leaf-row blocks unloaded until they enter the viewport.
Configuration
Section titled “Configuration”| Option | Default | Description |
|---|---|---|
groupBy | required | Grouping column props in server route order. |
blockSize | 100 | Direct children requested per block. |
purgeClosedGroups | false | Purge child route cache on collapse. |
maxConcurrentRequests | 4 | Limits simultaneous route block requests. |
blockLoadDebounceMs | 0 | Delays block load dispatch after scroll/materialization. |
quickFilter | undefined | Global filter payload forwarded to the server. |
api | undefined | Receives the client-side plugin controller. This is not a server request callback. |
query | undefined | Optional native polling, caching, retries and shared sources; see configuration types and defaults. |
loadRows | required | Server datasource for root groups, nested group routes, and final leaf rows. |
loadExpandedGroups | undefined | Optional one-request expand-all endpoint that returns flattened group rows with routes. |
Built-in shared route queries
Section titled “Built-in shared route queries”Keep loadRows(request, signal) and optional loadExpandedGroups(request, signal).
See the cancellation signal contract.
They now run through the shared Query engine automatically. The existing result
shapes, direct-child counts, totals, grouping fields and level parameters remain.
The plugin owns materialization/expansion; Query owns freshness, retries and shared
transport. The former per-model transport queue has been removed.
The optional query configuration supports source, reconcile, onStatus,
resource and snapshot consistency. Use createDataQueryContext from
@revolist/revogrid-pro to share a scope between grids. Its source-level concurrency
budget covers all views, routes, bulk reads and retries. Reconciliation receives
the original callback result shape and preserves application-owned proposals.
Hydration is silent and preserves history.
Default consistency is eventual. Regrouping and membership changes require source
invalidation; call source.accepted() after canonical accepted changes to also
fence off earlier reads. Parent/level-parameter changes reload affected children.
Collapse releases branch observers without cancelling another subscriber;
purgeClosedGroups makes the next expansion fetch fresh data. Bulk refresh preserves
user collapse state. The retained group tree has no independent size cap.
Query usage and configuration
Section titled “Query usage and configuration”See Server Data Queries for polling,
shared views,
caching,
retries,
lifecycle and the complete configuration types and defaults.
Your existing loader callback stays unchanged; add options inside query.
The query concepts are explained individually:
- Pages, blocks, routes and observers
- Polling, mount, focus and reconnect refetch
staleTimefreshness andgcTimecache retentionenabled, offline pauses andnetworkModeretry,retryDelayandretryOnMountmetaand callback policies- Contexts, sources, resources, deduplication and concurrency
- Invalidation, accepted writes and acceptance fences
- Eventual/snapshot consistency and deterministic ordering
- Pending edits, reconciliation, hydration and status
- Cancellation and destruction
For an application-owned query library/cache, set query: false. See
bypassing Query
for lifecycle behavior and the difference from query: { enabled: false }.