);
}
export function DataGridViewSelectDemo() {
const mounted = useMounted();
if (!mounted) {
return (
Loading...
);
}
return (
);
}
```
## 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
```bash
pnpm dlx @docyrus/cli add @docyrus/ui-data-grid-view-select
```
**Dependencies:**
- [@tanstack/react-table](https://www.npmjs.com/package/@tanstack/react-table)
- [lucide-react](https://www.npmjs.com/package/lucide-react)
- [react-querybuilder](https://www.npmjs.com/package/react-querybuilder)
## Usage
```tsx
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";
}
/>
```
## API Reference
### DataGridViewSelectProps
| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `table` | `Table` | -- | TanStack Table instance. Required for reading column definitions. |
| `variant` | `"dropdown" \| "horizontal-tabs" \| "vertical-tabs"` | `"dropdown"` | Visual style of the view selector. |
| `views` | `Array` | -- | 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` | -- | List of view IDs that should be marked as hidden. |
| `fields` | `Array` | -- | 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` | -- | 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` | -- | 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` | -- | 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. |