gridcn2.0.0
Add-on optionsSort, filter, and search

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.

SymbolPurposeGuide
useDataGridViewsKeeps the views and returns the state and the actionsSaved views
DataGridViewsRenders the toolbar buttonSaved views
labelsReplaces the strings of the menuSaved views
DataGridViewsStoragePersists the viewsSaved 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:

Prop

Type

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.

KeyEnglish defaultArguments
viewsViewsnone
modifiedModifiednone
loadingLoading views…none
emptyNo saved views yet.none
loadFailedSaved views could not be loaded.none
saveFailedYour last change could not be saved.none
limitThe limit of 50 views is reached.none
overLimitA 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
importedNameImported viewnone
retryRetrynone
setDefaultUse {name} as the default viewname
unsetDefaultStop using {name} as the default viewname
renameRename {name}name
deleteDelete {name}name
confirmDeleteConfirm delete {name}name
newViewNameView namenone
saveNewSave as new viewnone
updateActiveUpdate {name}name
confirmRenameSave namenone
cancelCancelnone
fileLabelView as JSONnone
exportViewExport active viewnone
importViewImport viewnone
savedSaved view {name}name
updatedUpdated view {name}name
renamedRenamed to {name}name
deletedDeleted view {name}name
appliedApplied view {name}name
importedImported view {name}, with a note of the left out count when it is above zeroname, dropped
exportedExported the active view as JSON belownone
exportTooLargeThis view is too large to export as text.none
importFailedAn import message for each reasonreason: "too-large", "limit", "loading", or "invalid"

Result

Prop

Type

The result reads and changes the views:

  • activeViewId and activeView name the open view, or are null.
  • modified is true when the grid differs from the active view.
  • overLimit names the part of the grid state that exceeds a view limit, and is false when 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. saveView then returns null and updateView returns false. See Limits.
  • defaultViewId names the view that opens first.
  • selectView(id) opens a view, and selectView(null) clears the active view. saveView(name) saves the grid state under a name. updateView(id) replaces a view with the grid state. Without an id, updateView and exportView use the active view. renameView(id, name) and deleteView(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.

On this page