DataView
NewData table for real apps: resizable and hideable columns, selection with bulk actions, saved views, server mode, and loading, empty and error states.
Installation
$ pnpm dlx shadcn@latest add @synccn/data-viewFirst time in this project? Connect synccn with one command.
Usage
import { DataView } from "@/components/ui/data-view";<DataView columns={columns} data={rows} rowKey={(r) => r.id} selectable bulkActions={(rows) => …} />API reference
Generated from the component's TypeScript types, so it always matches the code.
DataView
Data table for real apps: search, sort, column visibility and resizing, selection with bulk actions, saved views, and loading, empty and error states. Works on local data or as a view over a server (mode="server").
- columnsrequired
DataViewColumn<T>[]Column definitions.
- datarequired
T[]Rows. In server mode, only the current page.
- rowKeyrequired
(row: T) => stringStable id for each row (selection survives sorting and paging).
- mode
"client" | "server"Default
"client""client" sorts, searches and pages `data` itself; "server" reports state changes and shows `data` as is.
- rowCount
numberTotal rows on the server (server mode).
- onStateChange
(state: DataViewState) => voidCalled whenever search, sort, page or page size change. Fetch here in server mode.
- filter
(row: T) => booleanExtra filter applied before search (client mode), e.g. from a FilterBuilder.
- loading
booleanDefault
falseShow skeleton rows.
- error
React.ReactNodeShow an error with a retry button.
- onRetry
() => voidCalled by the retry button.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
Components
- Button for
Button - Checkbox for
Checkbox - Dropdown Menu for
DropdownMenu - Input for
Input - Pagination for
Pagination - Select for
Select
Helpers
- lib/utilscn (merges class names)
npm packages
- clsx for cn()
- tailwind-merge for cn()
- lucide-react for AlertCircle, ArrowDown, ArrowUp, ArrowUpDown, Bookmark, Columns3, Inbox, RotateCcw, Search, X
Keyboard
- TabMove between the toolbar, headers, resize handles and rows
- EnterOpen the focused row (when rows are clickable)
- ←or→Resize the column whose handle is focused
Accessibility
- Sortable headers are buttons and the table reports the sort with aria-sort.
- Selection checkboxes have labels; the header checkbox shows a mixed state when some rows on the page are selected.
- The row count is announced politely as you page, search and filter; loading sets aria-busy.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: alert, group, separator, toolbar
- ARIA attributes: aria-busy, aria-label, aria-live, aria-orientation, aria-pressed, aria-selected, aria-sort
- Keys handled: ArrowLeft, ArrowRight, Enter, Escape
- Shows a visible focus ring for keyboard users
- Announces changes to screen readers