Server-driven total count
experimental
Size the scrollbar from a server-reported total that is exact, estimated or unknown.
Live example
Expected behavior
With an exact count, dragging to 50% requests a window near row 600,000. An estimate shows ~1.1M and adjusts once the real end is found. Unknown grows as data arrives. Adding rows updates the count without moving the top row.
Source
const api = createGrid({
rows: [],
columns,
rowModel: 'remote',
remoteSource: {
async fetchWindow({ startIndex, endIndex, signal }) {
const res = await fetch(`/audit?from=${startIndex}&to=${endIndex}`, { signal });
const { rows, total } = await res.json();
return { rows, totalCount: total, countKind: 'exact' };
},
},
});
api.on('totalCountChanged', ({ previous, next }) => update(previous, next));
grid.setAttribute('aria-rowcount', String(ariaRowCount(api.getTotalCount(), api.getCountKind())));const api = createGrid({
rows: [],
columns,
rowModel: 'remote',
remoteSource: {
async fetchWindow({ startIndex, endIndex, signal }) {
const res = await fetch(`/audit?from=${startIndex}&to=${endIndex}`, { signal });
const { rows, total } = await res.json();
return { rows, totalCount: total, countKind: 'exact' };
},
},
});
api.on('totalCountChanged', ({ previous, next }) => update(previous, next));
grid.setAttribute('aria-rowcount', String(ariaRowCount(api.getTotalCount(), api.getCountKind())));const api = createGrid({
rows: [],
columns,
rowModel: 'remote',
remoteSource: {
async fetchWindow({ startIndex, endIndex, signal }) {
const res = await fetch(`/audit?from=${startIndex}&to=${endIndex}`, { signal });
const { rows, total } = await res.json();
return { rows, totalCount: total, countKind: 'exact' };
},
},
});
api.on('totalCountChanged', ({ previous, next }) => update(previous, next));
grid.setAttribute('aria-rowcount', String(ariaRowCount(api.getTotalCount(), api.getCountKind())));const api = createGrid({
rows: [],
columns,
rowModel: 'remote',
remoteSource: {
async fetchWindow({ startIndex, endIndex, signal }) {
const res = await fetch(`/audit?from=${startIndex}&to=${endIndex}`, { signal });
const { rows, total } = await res.json();
return { rows, totalCount: total, countKind: 'exact' };
},
},
});
api.on('totalCountChanged', ({ previous, next }) => update(previous, next));
grid.setAttribute('aria-rowcount', String(ariaRowCount(api.getTotalCount(), api.getCountKind())));// JavaScript interop module
const api = createGrid({
rows: [],
columns,
rowModel: 'remote',
remoteSource: {
async fetchWindow({ startIndex, endIndex, signal }) {
const res = await fetch(`/audit?from=${startIndex}&to=${endIndex}`, { signal });
const { rows, total } = await res.json();
return { rows, totalCount: total, countKind: 'exact' };
},
},
});
api.on('totalCountChanged', ({ previous, next }) => update(previous, next));
grid.setAttribute('aria-rowcount', String(ariaRowCount(api.getTotalCount(), api.getCountKind())));API reference
| Kind | Name | Type | Description |
|---|---|---|---|
| Property | WindowResult.countKind | — | 'exact', 'estimate' or 'unknown'. |
| Method | getTotalCount | — | The reported total, or undefined while unknown. |
| Event | totalCountChanged | — | Reports the previous and next count. |
| Option | maxVirtualHeightStrategy | — | 'scale' compresses huge heights, 'clamp' cuts them. |