Skip to content

Commit f129172

Browse files
feat(apollo-vertex): add data-table component to registry
Implements a powerful data table component built on TanStack Table with sorting, filtering, pagination, and row selection. Includes DataTable, DataTableColumnHeader, DataTablePagination, and DataTableViewOptions helper components. - Add @tanstack/react-table dependency - Create registry/data-table/data-table.tsx with composable components - Register data-table in registry.json with required dependencies - Add path alias to tsconfig.json - Create DataTableTemplate demo for documentation - Add vertex-components/data-table documentation page Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent 94ef083 commit f129172

8 files changed

Lines changed: 784 additions & 30 deletions

File tree

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
import { DataTableTemplate } from '@/templates/DataTableTemplate'
2+
3+
# Data Table
4+
5+
A powerful data table component built on [TanStack Table](https://tanstack.com/table) with sorting, filtering, pagination, and row selection.
6+
7+
<div className="not-prose my-8 rounded-lg border overflow-hidden">
8+
<DataTableTemplate />
9+
</div>
10+
11+
## Features
12+
13+
- **Sorting**: Click column headers to sort ascending, descending, or clear
14+
- **Pagination**: Built-in page navigation with configurable rows per page
15+
- **Row Selection**: Checkbox-based row selection with select all support
16+
- **Column Visibility**: Toggle column visibility via dropdown
17+
- **Column Header Actions**: Reusable header component with sort and hide options
18+
- **Flexible Columns**: Define columns with custom renderers, formatters, and actions
19+
20+
## Installation
21+
22+
```bash
23+
npx shadcn@latest add @uipath/data-table
24+
```
25+
26+
This component requires the following dependencies:
27+
28+
- `@tanstack/react-table` - Table state management and utilities
29+
- `lucide-react` - Icons
30+
- `table` - Base table primitives
31+
- `button` - Button component
32+
- `dropdown-menu` - Dropdown menu component
33+
- `select` - Select component (for rows per page)
34+
35+
## Usage
36+
37+
### 1. Define your columns
38+
39+
```tsx
40+
"use client"
41+
42+
import type { ColumnDef } from "@/components/ui/data-table"
43+
import { DataTableColumnHeader } from "@/components/ui/data-table"
44+
45+
type Payment = {
46+
id: string
47+
amount: number
48+
status: "pending" | "processing" | "success" | "failed"
49+
email: string
50+
}
51+
52+
export const columns: ColumnDef<Payment>[] = [
53+
{
54+
accessorKey: "status",
55+
header: ({ column }) => (
56+
<DataTableColumnHeader column={column} title="Status" />
57+
),
58+
},
59+
{
60+
accessorKey: "email",
61+
header: ({ column }) => (
62+
<DataTableColumnHeader column={column} title="Email" />
63+
),
64+
},
65+
{
66+
accessorKey: "amount",
67+
header: ({ column }) => (
68+
<DataTableColumnHeader column={column} title="Amount" />
69+
),
70+
cell: ({ row }) => {
71+
const formatted = new Intl.NumberFormat("en-US", {
72+
style: "currency",
73+
currency: "USD",
74+
}).format(row.getValue("amount"))
75+
return <div className="text-right font-medium">{formatted}</div>
76+
},
77+
},
78+
]
79+
```
80+
81+
### 2. Render the DataTable
82+
83+
```tsx
84+
import { DataTable } from "@/components/ui/data-table"
85+
import { columns } from "./columns"
86+
87+
export default function PaymentsPage({ data }: { data: Payment[] }) {
88+
return <DataTable columns={columns} data={data} />
89+
}
90+
```
91+
92+
## Composable Helpers
93+
94+
The data table exports additional components for building advanced table UIs:
95+
96+
### DataTableColumnHeader
97+
98+
A reusable column header with a dropdown for sorting and hiding columns.
99+
100+
```tsx
101+
import { DataTableColumnHeader } from "@/components/ui/data-table"
102+
103+
{
104+
accessorKey: "email",
105+
header: ({ column }) => (
106+
<DataTableColumnHeader column={column} title="Email" />
107+
),
108+
}
109+
```
110+
111+
### DataTablePagination
112+
113+
A standalone pagination component. The `DataTable` includes this by default, but you can also use it separately when building custom table layouts.
114+
115+
```tsx
116+
import { DataTablePagination } from "@/components/ui/data-table"
117+
118+
<DataTablePagination table={table} />
119+
```
120+
121+
### DataTableViewOptions
122+
123+
A column visibility toggle dropdown. Use this in a toolbar above the table.
124+
125+
```tsx
126+
import { DataTableViewOptions } from "@/components/ui/data-table"
127+
128+
<DataTableViewOptions table={table} />
129+
```
130+
131+
## Row Selection
132+
133+
Add a selection column using the `Checkbox` component:
134+
135+
```tsx
136+
import { Checkbox } from "@/components/ui/checkbox"
137+
138+
const columns: ColumnDef<Payment>[] = [
139+
{
140+
id: "select",
141+
header: ({ table }) => (
142+
<Checkbox
143+
checked={
144+
table.getIsAllPageRowsSelected() ||
145+
(table.getIsSomePageRowsSelected() && "indeterminate")
146+
}
147+
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
148+
aria-label="Select all"
149+
/>
150+
),
151+
cell: ({ row }) => (
152+
<Checkbox
153+
checked={row.getIsSelected()}
154+
onCheckedChange={(value) => row.toggleSelected(!!value)}
155+
aria-label="Select row"
156+
/>
157+
),
158+
enableSorting: false,
159+
enableHiding: false,
160+
},
161+
// ... other columns
162+
]
163+
```

apps/apollo-vertex/next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
import "./.next/types/routes.d.ts";
3+
import "./.next/dev/types/routes.d.ts";
44

55
// NOTE: This file should not be edited
66
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

apps/apollo-vertex/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@radix-ui/react-toggle-group": "^1.1.11",
4949
"@radix-ui/react-tooltip": "^1.2.8",
5050
"@tailwindcss/postcss": "^4.1.17",
51+
"@tanstack/react-table": "^8.21.3",
5152
"@uipath/auth-react": "^1.1.6",
5253
"@vercel/analytics": "^1.5.0",
5354
"class-variance-authority": "^0.7.1",

apps/apollo-vertex/registry.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,20 @@
191191
}
192192
]
193193
},
194+
{
195+
"name": "data-table",
196+
"type": "registry:ui",
197+
"title": "Data Table",
198+
"description": "A data table component built on TanStack Table with sorting, filtering, pagination, and row selection.",
199+
"dependencies": ["@tanstack/react-table", "lucide-react"],
200+
"registryDependencies": ["table", "button", "dropdown-menu", "select"],
201+
"files": [
202+
{
203+
"path": "registry/data-table/data-table.tsx",
204+
"type": "registry:ui"
205+
}
206+
]
207+
},
194208
{
195209
"name": "dialog",
196210
"type": "registry:ui",

0 commit comments

Comments
 (0)