Intelligent GridDocumentation

Server data

Ways to get rows from a backend into the grid, besides setData():

Need Use
Page by page as the user scrolls, over HTTP append mode with load and fetch
Page by page over one connection, with live changes from other users append mode with socket
Every row, in blocks, with progress loadStream() (Server-Sent Events)
Changes your own code receives (polling, a message bus) applyServerChanges()

WebSocket and Server-Sent Events are alternatives to fetch, not replacements. They need sorla-db 1.7.1 or later.

Server-Sent Events: loading in blocks

const stream = grid.loadStream('/api/orders/stream', {
    headers: { Authorization: `Bearer ${token}` },
    onProgress: ({ loaded, total }) => (bar.value = total ? loaded / total : 0)
});
const state = await stream.done;   // { loaded, total, blocks, errors, ... }
stream.close();                    // stops early

The server sends the rows in named events (the sorla-db stream protocol):

event: meta
data: {"total": 100000}

id: 1
event: rows
data: [{"id": 1, ...}, ... 5000 rows ...]

event: end
data: {}

Events: streamEnd (the final state) and streamError ({ error }).

A Node example of the endpoint is in scripts/demo-api.ts (/api/orders/stream): it waits for drain when the browser reads slower than the server writes.

applyServerChanges

grid.applyServerChanges({ rows: [{ id: 7, qty: 3 }, { id: 9001, name: 'New', qty: 1 }] });
grid.applyServerChanges({ type: 'delete', ids: [12, 13] });
// → { inserted: ['9001'], updated: ['7'], removed: ['12', '13'] }

Try it

npm run demo starts a backend with 100 000 orders kept in a sorla-db collection on the server:

Example Shows
fetch-pages.html pages over HTTP that add to the grid; filters sent as where
websocket.html pages over a WebSocket, rows changed by "another user" every 3 s
sse-stream.html 100 000 rows in blocks of 5 000, with progress

Edit this page on GitHub