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

Manual

Install the required dependencies:

bash
npm install @tanstack/react-table

The component uses the Table, Button, Checkbox, Input, and Select components.

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

PropTypeDefaultDescription
columnsColumnDef[]-Column definitions for the table
dataTData[]-Data array to display in the table
searchColumnstring-Column key to enable search filtering
showSearchbooleantrueShow/hide the search input
searchPlaceholderstring"Search..."Placeholder text for search input
showRowSelectionbooleantrueShow/hide row selection count
showRowsPerPagebooleantrueShow/hide rows per page selector
showPageInfobooleantrueShow/hide page information
showFirstLastButtonsbooleantrueShow/hide first/last page buttons
showPreviousNextButtonsbooleantrueShow/hide previous/next buttons
pageSizeOptionsnumber[][10, 20, 25, 30, 40, 50]Available page size options
rowSelectionTextstring"row(s) selected"Text for row selection display
rowsPerPageTextstring"Rows per page"Label for rows per page selector
pageInfoFormatfunction-Function to format page info display
onSearchfunction-Callback when search value changes
onPageChangefunction-Callback when page changes
onPageSizeChangefunction-Callback when page size changes

DataTableColumnHeader

PropTypeDefaultDescription
columnColumn-TanStack Table column instance
titlestring-Display title for the column
align"start" | "center" | "end""start"Text alignment for column header
canSortbooleantrueWhether column can be sorted
canHidebooleantrueWhether column can be hidden

External Documentation