Data Grid View Select
A view selector with integrated view editor for DataGrid. Supports dropdown, horizontal-tabs, and vertical-tabs variants with full CRUD operations on saved views.
Overview
DataGridViewSelect combines a view selector and a view editor into a single component. Users can switch between saved views to instantly apply column visibility, ordering, pinning, sorting, grouping, and filter configurations to a @tanstack/react-table instance.
When editable is enabled, users get full view management: create new views, edit existing ones via a dialog with a dual-box column picker, rename, reorder, delete, and hide/unhide views through a context menu.
The DataGridViewEditor sub-component is also exported separately for standalone use outside of the view selector.
Installation
pnpm dlx @docyrus/cli add @docyrus/ui-data-grid-view-selectnpx shadcn@latest add badge button collapsible command dialog dropdown-menu input label popover select sortable tabs textareapnpm add @tanstack/react-table react-querybuilderUsage
import {
DataGridViewSelect,
DataGridViewEditor
} from "@docyrus/ui/components/data-grid-view-select";
import type {
DataGridViewSelectProps,
DataGridViewSelectVariant,
DataGridViewEditorProps
} from "@docyrus/ui/components/data-grid-view-select";
import type { SavedDataGridView } from "@docyrus/ui/components/data-grid";
<DataGridViewSelect
table={table}
variant="horizontal-tabs"
views={views}
activeViewId={activeViewId}
onViewChange={(view) => {
setActiveViewId(view.id);
applyViewToTable(table, view);
}}
editable
onViewSave={handleSave}
onViewDelete={handleDelete}
onViewCreate={handleCreate}
onViewHide={handleHide}
onViewUnhide={handleUnhide}
hiddenViewIds={hiddenViewIds}
fields={fields}
/>Variants
| Variant | Description |
|---|---|
dropdown | Combobox-style dropdown selector (default). Best for limited toolbar space. |
horizontal-tabs | Inline horizontal tab bar. Best for prominent view switching. |
vertical-tabs | Vertical tab list. Best for sidebar or stacked layouts. |
Editable Mode
When editable={true}, the component adds:
- Context menu on each view tab/item with Rename, Edit, Duplicate, Hide, and Delete actions
- Add button (+) to create a new view from a blank template or duplicate the active view
- View Editor Dialog with sections:
- General — name, description, row height, display mode
- Columns — dual-box column picker (available / visible) with drag-to-reorder
- Sorting — sort by column + direction
- Row Grouping — pick a groupable column (the field types listed by
useDocyrusDataGrid); honorsdefaultRowGroupingColumn - Paging — toggle the standard paging footer, pick the mode (
standard/virtual-scroll), and choose a page size from theDATA_GRID_PAGE_SIZE_OPTIONSset (25 / 50 / 100 / 200 / 250 / 500, default50) - Filters —
react-querybuilderquery builder (whenfieldsis provided) - Row / Cell Color Rules — JSONata-driven conditional coloring
Column Picker
The view editor includes a dual-box column picker. Available (hidden) columns appear on the left; visible columns appear on the right with drag-and-drop reordering. Columns with meta.group set on their column definition are displayed under collapsible group headers.
Standalone Editor
DataGridViewEditor can be used independently as a dialog for editing a single view:
import { DataGridViewEditor } from "@docyrus/ui/components/data-grid-view-select";
<DataGridViewEditor
table={table}
value={currentView}
onSave={handleSave}
onDelete={handleDelete}
fields={fields}
trigger={<Button>Edit View</Button>}
/>API Reference
DataGridViewSelectProps
| Prop | Type | Default | Description |
|---|---|---|---|
table | Table<TData> | -- | TanStack Table instance. Required for reading column definitions. |
variant | "dropdown" | "horizontal-tabs" | "vertical-tabs" | "dropdown" | Visual style of the view selector. |
views | Array<SavedDataGridView> | -- | List of saved views to display. |
activeViewId | string | -- | Controlled active view ID. |
defaultActiveViewId | string | -- | Uncontrolled initial active view ID. |
onViewChange | (view: SavedDataGridView) => void | -- | Called when the user selects a different view. |
onViewSave | (view: SavedDataGridView) => void | -- | Called when a view is saved (edited) via the editor dialog. |
onViewDelete | (viewId: string) => void | -- | Called when a view is deleted via context menu or editor. |
onViewCreate | (view: SavedDataGridView, position?: { afterViewId?: string; beforeViewId?: string }) => void | -- | Called when a new view is created. Includes optional position hint. |
onViewHide | (viewId: string) => void | -- | Called when a view is hidden via context menu. |
onViewUnhide | (viewId: string) => void | -- | Called when a hidden view is unhidden. |
hiddenViewIds | Array<string> | -- | List of view IDs that should be marked as hidden. |
fields | Array<FullField> | -- | Field definitions for the filter section in the view editor. When provided, enables the filter builder. |
editable | boolean | false | Enables view CRUD operations (add, edit, delete, hide/unhide, context menu). |
disabled | boolean | -- | Disables the entire selector. |
placeholder | string | -- | Placeholder text for the dropdown variant when no view is selected. |
className | string | -- | Additional CSS class names. |
DataGridViewEditorProps
| Prop | Type | Default | Description |
|---|---|---|---|
table | Table<TData> | -- | TanStack Table instance. |
open | boolean | -- | Controlled open state. |
onOpenChange | (open: boolean) => void | -- | Called when dialog open state changes. |
value | SavedDataGridView | -- | The view to edit. When undefined, creates a new view. |
views | Array<SavedDataGridView> | -- | List of all views (used for the view switcher inside the dialog). |
onSave | (view: SavedDataGridView) => void | -- | Called when the user saves the view. |
onDelete | (viewId: string) => void | -- | Called when the user deletes the view. |
onCancel | () => void | -- | Called when the user cancels editing. |
onViewSwitch | (viewId: string) => void | -- | Called when the user switches to another view from inside the dialog. |
fields | Array<FullField> | -- | Field definitions for the filter section. |
disabled | boolean | -- | Disables all form controls inside the editor. |
showDelete | boolean | -- | Whether to show the delete button. |
trigger | ReactNode | -- | Custom trigger element for the dialog. |
Credits
Data Grid
A virtualized, editable spreadsheet-like data grid with sorting, filtering, grouping, cell selection, and keyboard navigation.
Data Import Wizard
Multi-step modal wizard that turns an Excel/CSV upload into Docyrus data source records — drag-drop, auto-mapped column→field assignment, per-type config, value-renderer preview, and a result summary.