Data Table
A powerful, fully customizable data table built with TanStack Table. Features dynamic configuration, advanced sorting, filtering, pagination, and row selection.
John | Smith | john.smith@company.com | Engineering | Senior | $95,000.00 | 2022-03-15 | active | New York | ||
Sarah | Johnson | sarah.johnson@company.com | Marketing | Manager | $87,000.00 | 2021-08-22 | active | San Francisco | ||
Mike | Williams | mike.williams@company.com | Sales | Lead | $78,000.00 | 2023-01-10 | active | London | ||
Emily | Brown | emily.brown@company.com | Design | Senior | $82,000.00 | 2022-11-05 | active | Toronto | ||
David | Jones | david.jones@company.com | HR | Director | $105,000.00 | 2020-06-18 | active | Berlin | ||
Lisa | Garcia | lisa.garcia@company.com | Finance | Manager | $92,000.00 | 2021-12-03 | inactive | Tokyo | ||
Chris | Miller | chris.miller@company.com | Operations | Specialist | $68,000.00 | 2023-04-20 | pending | Sydney | ||
Anna | Davis | anna.davis@company.com | Engineering | Junior | $72,000.00 | 2023-09-12 | active | New York | ||
Tom | Rodriguez | tom.rodriguez@company.com | Marketing | Intern | $45,000.00 | 2024-01-08 | active | San Francisco | ||
Maria | Martinez | maria.martinez@company.com | Sales | Senior | $85,000.00 | 2022-07-14 | active | London |
0 of 20 employees selected.
Employees per page
Page 1 of 2
Installation
CLI
bash
npx fivui add data-table
Usage
Basic Usage
tsx
import { DataTable, DataTableColumnHeader } from "@/components/ui/data-table"import { ColumnDef } from "@tanstack/react-table"
type User = { id: string name: string email: string status: string}
const columns: ColumnDef<User>[] = [ { accessorKey: "name", header: ({ column }) => ( <DataTableColumnHeader column={column} title="Name" /> ), }, { accessorKey: "email", header: ({ column }) => ( <DataTableColumnHeader column={column} title="Email" /> ), }, { accessorKey: "status", header: ({ column }) => ( <DataTableColumnHeader column={column} title="Status" /> ), },]
const data: User[] = [ { id: "1", name: "John Doe", email: "john@example.com", status: "active" }, // ... more data]
export function UserTable() { return ( <DataTable columns={columns} data={data} searchColumn="email" /> )}
Advanced Configuration
tsx
export function AdvancedUserTable() { return ( <DataTable columns={columns} data={data} // Search configuration searchColumn="email" searchPlaceholder="Filter by email address..." showSearch={true} onSearch={(value) => console.log('Searching:', value)} // Pagination configuration showRowSelection={true} showRowsPerPage={true} showPageInfo={true} showFirstLastButtons={true} showPreviousNextButtons={true} pageSizeOptions={[5, 10, 25, 50, 100]} // Custom text rowSelectionText="users selected" rowsPerPageText="Users per page" pageInfoFormat={(current, total) => `${current} / ${total}`} // Event handlers onPageChange={(page) => console.log('Page:', page)} onPageSizeChange={(size) => console.log('Size:', size)} /> )}
Features
🔍 Advanced Search
Filter data by any column with customizable search input and placeholder text.
📊 Smart Sorting
Click column headers to sort data. Configure which columns can be sorted.
📄 Flexible Pagination
Customizable pagination with configurable page sizes and navigation buttons.
✅ Row Selection
Select individual rows or all rows with checkbox controls and custom selection text.
👁️ Column Visibility
Show or hide columns dynamically with the column visibility dropdown.
🎨 Full Customization
Every aspect is configurable through props - text, behavior, and appearance.
Column Header Configuration
Use the DataTableColumnHeader component for advanced column functionality.
Column Header Examples
tsx
// Basic sortable column{ accessorKey: "name", header: ({ column }) => ( <DataTableColumnHeader column={column} title="Name" /> ),}
// Right-aligned column (for numbers){ accessorKey: "amount", header: ({ column }) => ( <DataTableColumnHeader column={column} title="Amount" align="end" /> ),}
// Non-sortable column{ accessorKey: "actions", header: ({ column }) => ( <DataTableColumnHeader column={column} title="Actions" canSort={false} /> ),}
// Non-hideable column{ accessorKey: "id", header: ({ column }) => ( <DataTableColumnHeader column={column} title="ID" canHide={false} /> ),}
API Reference
DataTable
Prop | Type | Default | Description |
---|---|---|---|
columns | ColumnDef[] | - | Column definitions for the table |
data | TData[] | - | Data array to display in the table |
searchColumn | string | - | Column key to enable search filtering |
showSearch | boolean | true | Show/hide the search input |
searchPlaceholder | string | "Search..." | Placeholder text for search input |
showRowSelection | boolean | true | Show/hide row selection count |
showRowsPerPage | boolean | true | Show/hide rows per page selector |
showPageInfo | boolean | true | Show/hide page information |
showFirstLastButtons | boolean | true | Show/hide first/last page buttons |
showPreviousNextButtons | boolean | true | Show/hide previous/next buttons |
pageSizeOptions | number[] | [10, 20, 25, 30, 40, 50] | Available page size options |
rowSelectionText | string | "row(s) selected" | Text for row selection display |
rowsPerPageText | string | "Rows per page" | Label for rows per page selector |
pageInfoFormat | function | - | Function to format page info display |
onSearch | function | - | Callback when search value changes |
onPageChange | function | - | Callback when page changes |
onPageSizeChange | function | - | Callback when page size changes |
DataTableColumnHeader
Prop | Type | Default | Description |
---|---|---|---|
column | Column | - | TanStack Table column instance |
title | string | - | Display title for the column |
align | "start" | "center" | "end" | "start" | Text alignment for column header |
canSort | boolean | true | Whether column can be sorted |
canHide | boolean | true | Whether column can be hidden |