Skip to Content
✨ QuickCode UI keeps growing! More components, more features, and more ways to make your projects shine. Stay tuned & maybe… hire me or sponsor me 😉 
DocumentationTable

Table

A powerful and flexible data table component with advanced features including sorting, filtering, pagination, row selection, and export capabilities. Built using compound components for maximum flexibility.

Install Dependencies

npx
quickcode-ui add Table

Example

Basic Table

View
Edit
Delete
iPhone 15$999Active
MacBook Air$1299Active
Nike Air Max$120Active
Samsung TV$799Inactive
Adidas Hoodie$80Active
Sony Headphones$299Active
Levi's Jeans$89Active
Dell Monitor$349Active
Under Armour Shirt$35Active
Canon Camera$650Inactive
Showing 1 to 10 of 20 results

Expandable Table

Expand
View
Edit
SJ
Sarah Johnson
sarah@company.comManager
MC
Mike Chen
mike@company.comDeveloper
EW
Emma Wilson
emma@company.comDesigner
DK
David Kim
david@company.comAnalyst
LW
Lisa Wang
lisa@company.comDeveloper
JB
James Brown
james@company.comManager
AD
Anna Davis
anna@company.comHR Specialist
TW
Tom Wilson
tom@company.comDeveloper
MG
Maria Garcia
maria@company.comDesigner
CL
Chris Lee
chris@company.comAnalyst
Showing 1 to 10 of 20 results

Table.Root Props

PropTypeDefaultDescription
dataT[]-Array of data objects to display
columnsColumn<T>[]-Column configuration array
childrenReact.ReactNode-Child components
classNamestring-Additional CSS classes
loadingbooleanfalseShow loading state
errorstring-Error message to display
totalItemsnumber-Total number of items for server-side pagination
serverSidebooleanfalseEnable server-side data handling
selectablebooleanfalseEnable row selection
expandablebooleanfalseEnable row expansion
multiSortbooleanfalseAllow multiple column sorting
stickyHeaderbooleanfalseMake table header sticky
showPaginationbooleantrueShow pagination controls
showSearchbooleantrueShow search input
showExportbooleanfalseShow export buttons
columnResizablebooleanfalseEnable column resizing
rowActionsRowAction<T>[][]Array of row actions
searchPlaceholderstring"Search..."Search input placeholder
emptyMessagestring"No data available"Empty state message
pageSizenumber10Default page size
onSort(sorts: SortState[]) => void-Sort change callback
onSearch(query: string) => void-Search callback
onPageChange(pagination: PaginationState) => void-Page change callback
onRowSelect(selectedRows: T[], row: T, isSelected: boolean) => void-Row selection callback
onRowClick(row: T, index: number) => void-Row click callback
onRowDoubleClick(row: T, index: number) => void-Row double click callback
onRowExpand(row: T, isExpanded: boolean) => void-Row expand callback
onExport(type: "csv" | "json", data: T[]) => void-Export callback

Column Props

PropTypeDefaultDescription
keykeyof T | string-Data key or accessor string
titlestring-Column header title
sortablebooleanfalseEnable column sorting
filterablebooleanfalseEnable column filtering
render(row: T, index: number) => React.ReactNode-Custom cell render function
widthstring | number-Column width
minWidthstring | number-Minimum column width
maxWidthstring | number-Maximum column width
align"left" | "center" | "right""left"Text alignment
stickybooleanfalseMake column sticky
tooltipstring-Column header tooltip
classNamestring-Additional CSS classes

RowAction Props

PropTypeDefaultDescription
labelstring-Action label
onClick(row: T, index: number) => void-Click handler
iconReact.ReactNode-Action icon
colorstring-Icon color
disabled(row: T) => boolean-Disable condition function
tooltipstring-Action tooltip

Table.Toolbar Props

PropTypeDefaultDescription
childrenReact.ReactNode-Additional toolbar content
classNamestring-Additional CSS classes

Table.Container Props

PropTypeDefaultDescription
childrenReact.ReactNode-Table content
classNamestring-Additional CSS classes

Table.Header Props

PropTypeDefaultDescription
childrenReact.ReactNode-Header rows
classNamestring-Additional CSS classes

Table.Body Props

PropTypeDefaultDescription
childrenReact.ReactNode-Body rows
classNamestring-Additional CSS classes

Table.Row Props

PropTypeDefaultDescription
childrenReact.ReactNode-Row cells
classNamestring-Additional CSS classes
onClick() => void-Row click handler
onDoubleClick() => void-Row double click handler

Table.Head Props

PropTypeDefaultDescription
childrenReact.ReactNode-Header cell content
columnColumn<T>-Column configuration
classNamestring-Additional CSS classes
sortableboolean-Override column sortable setting
filterableboolean-Override column filterable setting

Table.Cell Props

PropTypeDefaultDescription
childrenReact.ReactNode-Cell content
classNamestring-Additional CSS classes
align"left" | "center" | "right""left"Text alignment

Table.DataRow Props

PropTypeDefaultDescription
rowT-Data row object
indexnumber-Row index
children(row: T, index: number) => React.ReactNode-Expanded content render function
classNamestring-Additional CSS classes

Table.Pagination Props

PropTypeDefaultDescription
classNamestring-Additional CSS classes

Usage Examples

Basic Table Setup

import { Table, Column, RowAction } from "@/components/ui/Table"; import { Button } from "@/components/ui/Button"; import { Edit, Trash2 } from "lucide-react"; const data = [ { id: 1, name: "John Doe", email: "john@example.com", role: "Admin" }, { id: 2, name: "Jane Smith", email: "jane@example.com", role: "User" }, ]; const columns: Column<User>[] = [ { key: "name", title: "Name", sortable: true }, { key: "email", title: "Email", sortable: true }, { key: "role", title: "Role", filterable: true }, ]; export function UserTable() { return ( <Table.Root data={data} columns={columns} selectable showSearch> <Table.Toolbar> <Button>Add User</Button> </Table.Toolbar> <Table.Container> <Table.Header> <Table.Row> <Table.SelectHeader /> {columns.map((column) => ( <Table.Head key={column.key as string} column={column}> {column.title} </Table.Head> ))} </Table.Row> </Table.Header> <Table.Body /> </Table.Container> <Table.Pagination /> </Table.Root> ); }

Advanced Table with Expandable Rows & Actions

import { Table, Column, RowAction } from "@/components/ui/Table"; import { Button } from "@/components/ui/Button"; import { Edit, Trash2, Eye, Plus } from "lucide-react"; interface Employee { id: number; name: string; email: string; department: string; salary?: number; phone?: string; address?: string; } const employees: Employee[] = [ { id: 1, name: "Sarah Johnson", email: "sarah@company.com", department: "Engineering", salary: 95000, phone: "555-0101", address: "123 Main St, NY", }, ]; const columns: Column<Employee>[] = [ { key: "name", title: "Name", sortable: true, render: (row) => ( <div className="flex items-center gap-3"> <div className="w-8 h-8 bg-primary rounded-full flex items-center justify-center text-primary-foreground text-sm"> {row.name .split(" ") .map((n) => n[0]) .join("")} </div> <span className="font-medium">{row.name}</span> </div> ), }, { key: "email", title: "Email", sortable: true }, { key: "department", title: "Department", filterable: true }, ]; const rowActions: RowAction<Employee>[] = [ { label: "View", icon: <Eye size={16} />, onClick: (row) => console.log("View:", row.name), }, { label: "Edit", icon: <Edit size={16} />, onClick: (row) => console.log("Edit:", row.name), }, { label: "Delete", icon: <Trash2 size={16} />, onClick: (row) => console.log("Delete:", row.name), }, ]; export function EmployeeTable() { return ( <Table.Root data={employees} columns={columns} expandable selectable showSearch showExport rowActions={rowActions} onRowSelect={(selected) => console.log("Selected:", selected.length)} > <Table.Toolbar> <Button className="flex items-center gap-2"> <Plus size={16} /> Add Employee </Button> </Table.Toolbar> <Table.Container> <Table.Header> <Table.Row> <Table.SelectHeader /> <Table.ExpandHeader /> {columns.map((column) => ( <Table.Head key={column.key as string} column={column} sortable={column.sortable} filterable={column.filterable} > {column.title} </Table.Head> ))} <Table.ActionsHeader /> </Table.Row> </Table.Header> <Table.Body renderExpandedRow={(row) => ( <div className="p-4 space-y-2"> <h4 className="font-semibold">Details for {row.name}</h4> <div className="grid grid-cols-2 gap-4 text-sm"> <div> <strong>Salary:</strong> ${row.salary?.toLocaleString()} </div> <div> <strong>Phone:</strong> {row.phone} </div> <div> <strong>Address:</strong> {row.address} </div> </div> </div> )} /> </Table.Container> <Table.Pagination /> </Table.Root> ); }
Last updated on