Remote data source contract
experimental
Load rows by index window from a simulated server without holding the full dataset.
Live example
Expected behavior
On mount one request covers the viewport plus buffer. Scrolling to an unloaded region requests only that range, and the log shows each range and its time to resolve.
Source
const api = createGrid({
rows: [],
columns,
rowModel: 'remote',
remoteSource: {
async fetchWindow({ startIndex, endIndex, signal }) {
const res = await fetch(`/orders?from=${startIndex}&to=${endIndex}`, { signal });
const { rows, total } = await res.json();
return { rows, totalCount: total };
},
},
});
api.requestWindow(0, 20);const api = createGrid({
rows: [],
columns,
rowModel: 'remote',
remoteSource: {
async fetchWindow({ startIndex, endIndex, signal }) {
const res = await fetch(`/orders?from=${startIndex}&to=${endIndex}`, { signal });
const { rows, total } = await res.json();
return { rows, totalCount: total };
},
},
});
api.requestWindow(0, 20);const api = createGrid({
rows: [],
columns,
rowModel: 'remote',
remoteSource: {
async fetchWindow({ startIndex, endIndex, signal }) {
const res = await fetch(`/orders?from=${startIndex}&to=${endIndex}`, { signal });
const { rows, total } = await res.json();
return { rows, totalCount: total };
},
},
});
api.requestWindow(0, 20);const api = createGrid({
rows: [],
columns,
rowModel: 'remote',
remoteSource: {
async fetchWindow({ startIndex, endIndex, signal }) {
const res = await fetch(`/orders?from=${startIndex}&to=${endIndex}`, { signal });
const { rows, total } = await res.json();
return { rows, totalCount: total };
},
},
});
api.requestWindow(0, 20);// JavaScript interop module
const api = createGrid({
rows: [],
columns,
rowModel: 'remote',
remoteSource: {
async fetchWindow({ startIndex, endIndex, signal }) {
const res = await fetch(`/orders?from=${startIndex}&to=${endIndex}`, { signal });
const { rows, total } = await res.json();
return { rows, totalCount: total };
},
},
});
api.requestWindow(0, 20);API reference
| Kind | Name | Type | Description |
|---|---|---|---|
| Option | rowModel | — | Set to 'remote' to load rows through remoteSource. |
| Method | remoteSource.fetchWindow | — | Receives startIndex (inclusive), endIndex (exclusive) and requestId, and resolves rows and an optional totalCount. |
| Method | requestWindow | — | Fetches only the uncached, not in-flight rows of a range. |
| Event | remoteWindowLoaded | — | Reports the range, row count and known total. |
| Event | remoteWindowFailed | — | Reports the range and the error of a failed request. |