Saved views options
Look up the options of useDataGridViews, the result it returns, the props of DataGridViews, and the storage adapter types.
useDataGridViews keeps the saved views of a grid and returns the state and the actions. DataGridViews renders the toolbar button on top of it. The behavior is on Saved views.
| Symbol | Purpose | Guide |
|---|---|---|
useDataGridViews | Keeps the views and returns the state and the actions | Saved views |
DataGridViews | Renders the toolbar button | Saved views |
labels | Replaces the strings of the menu | Saved views |
DataGridViewsStorage | Persists the views | Saved views |
DataGridViews is the ready button. useDataGridViews drives a control of your own, such as this select:
import {
DataGridViews,
useDataGridViews,
} from "@/components/data-grid-views/data-grid-views";
export function ViewsButton() {
return <DataGridViews storage="orders-views" />;
}
export function ViewsSelect() {
const { views, activeViewId, selectView } = useDataGridViews({
storage: "orders-views",
});
return (
<select
value={activeViewId ?? ""}
onChange={(event) => selectView(event.target.value || null)}
>
<option value="">No view</option>
{views.map((view) => (
<option key={view.id} value={view.id}>
{view.name}
</option>
))}
</select>
);
}Render each one inside DataGridProvider.
Options
Prop
Type
DataGridViews
DataGridViews takes these options and two more props:
Labels
labels takes a partial DataGridViewsLabels. It merges over the labels.views of the grid, which merges over the defaults. A function field receives the argument shown.
| Key | English default | Arguments |
|---|---|---|
views | Views | none |
modified | Modified | none |
loading | Loading views… | none |
empty | No saved views yet. | none |
loadFailed | Saved views could not be loaded. | none |
saveFailed | Your last change could not be saved. | none |
limit | The limit of 50 views is reached. | none |
overLimit | A line for the OverLimitPart that is over a limit, such as The sorts are over the view limit of 64. Remove one to save the view. | part |
importedName | Imported view | none |
retry | Retry | none |
setDefault | Use {name} as the default view | name |
unsetDefault | Stop using {name} as the default view | name |
rename | Rename {name} | name |
delete | Delete {name} | name |
confirmDelete | Confirm delete {name} | name |
newViewName | View name | none |
saveNew | Save as new view | none |
updateActive | Update {name} | name |
confirmRename | Save name | none |
cancel | Cancel | none |
fileLabel | View as JSON | none |
exportView | Export active view | none |
importView | Import view | none |
saved | Saved view {name} | name |
updated | Updated view {name} | name |
renamed | Renamed to {name} | name |
deleted | Deleted view {name} | name |
applied | Applied view {name} | name |
imported | Imported view {name}, with a note of the left out count when it is above zero | name, dropped |
exported | Exported the active view as JSON below | none |
exportTooLarge | This view is too large to export as text. | none |
importFailed | An import message for each reason | reason: "too-large", "limit", "loading", or "invalid" |
Result
Prop
Type
The result reads and changes the views:
activeViewIdandactiveViewname the open view, or arenull.modifiedistruewhen the grid differs from the active view.overLimitnames the part of the grid state that exceeds a view limit, and isfalsewhen none does. The limits are 64 sorts, 64 filters, 16 filter groups, 1,000 characters in a filter value, and 1,000 entries in a value list. A search text holds up to 500 characters. The layout limits are a width of 10,000 px and 1,000 entries in a list. State of a column that the grid lacks is not a limit.saveViewthen returnsnullandupdateViewreturnsfalse. See Limits.defaultViewIdnames the view that opens first.selectView(id)opens a view, andselectView(null)clears the active view.saveView(name)saves the grid state under a name.updateView(id)replaces a view with the grid state. Without anid,updateViewandexportViewuse the active view.renameView(id, name)anddeleteView(id)edit the list.setDefaultView(id)picks the default view.
A DataGridView has an id, a name, and a DataGridViewState. The state holds the sorts, groupBy, the filters, the search text, the search options, and the column layout. The storage adapter persists a DataGridViewsDocument: its version, its views, and its defaultViewId.
importView(text, { name }) returns an ImportViewResult: { ok: true, view, dropped } or { ok: false, reason }. name applies when the file has none. exportView(id) returns the view as compact JSON text, or null for an unknown id or a view over 100,000 characters.
Storage
Prop
Type
createLocalStorageViewsStorage(key) returns the default adapter. createMemoryViewsStorage(seed?) returns an adapter that keeps views for the life of the page.
Server mode
A view stores the grid state only. Opening a view calls the change callbacks of a server grid, and a view saves no page number. See Saved views: Server mode.
Related
- Saved views: how views behave
- URL state options: the same state in the URL