Data and row ids
Rows are plain objects; getRowId keeps selection and focus across setData, and noRowsOverlay and loadingOverlay set the empty and loading messages.
Rows are ordinary objects. Without getRowId rows are identified by position, so replacing the data clears the selection. With it, the selection survives setData as long as the ids still exist.
const grid = createGrid(el, {
columns,
data: rows,
getRowId: row => String(row.id), // keeps selection and focus stable across setData
});
grid.setData(await fetch('/api/orders').then(r => r.json()));
grid.getData(); // rows as passed in
grid.getDisplayedRowCount(); // rows after filtersEmpty and loading messages
When there are no rows the grid shows a message in its language; when the filters hide every row it says so instead. noRowsOverlay replaces that text with your own, or with an element such as a "Clear filters" button, and loadingOverlay sets what shows while server rows load. showOverlay() shows either one yourself, for example while your own request runs.
createGrid(el, {
columns,
data: [],
noRowsOverlay: ({ filtered }) => (filtered ? 'No rows match the filters' : 'No orders yet'),
loadingOverlay: 'Loading…',
});
grid.showOverlay('loading'); // while your own request runs
grid.setData(await loadOrders());
grid.showOverlay(null); // back to automatic| Name | Type | Description |
|---|---|---|
noRowsOverlay | string | ({ filtered }) => string | HTMLElement | Shown when there are no rows; filtered is true when the filters hide every row. |
loadingOverlay | string | ({ filtered }) => string | HTMLElement | Shown while server rows load. |
showOverlay(kind | null) | void | Show 'loading' or 'noRows' yourself, for example while your own request runs; null goes back to automatic. |