Table parts with the same names as in shadcn/ui, rendered on the server as plain <table> markup with no JavaScript. A table wider than its box scrolls inside its container: the scrollbar stays visible, the edge that hides content fades out, and browsers with ::scroll-button() draw round arrow buttons. For sorting, search and pagination use Data Table.
Browser Support
Limited availability2 featuresDetails
Fades the edge that hides more columns. Without it there is no fade, the scrollbar still shows that the table scrolls.
Round arrow buttons on the edges, drawn by the browser. Without them scroll with the scrollbar, Shift + wheel or a trackpad.
Preview
| Invoice | Status | Method | Amount |
|---|---|---|---|
| INV001 | Paid | Credit card | $250.00 |
| INV002 | Pending | PayPal | $150.00 |
| INV003 | Unpaid | Bank transfer | $350.00 |
| INV004 | Paid | Credit card | $450.00 |
| INV005 | Paid | PayPal | $550.00 |
| Total | $1,750.00 | ||
Installation
Usage
import {
Table,
TableBody,
TableCaption,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"
export default function Example() {
return (
<Table>
<TableCaption>A list of your recent invoices.</TableCaption>
<TableHeader>
<TableRow>
<TableHead className="w-24">Invoice</TableHead>
<TableHead>Status</TableHead>
<TableHead className="text-right">Amount</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow>
<TableCell className="font-medium">INV001</TableCell>
<TableCell>Paid</TableCell>
<TableCell className="text-right">$250.00</TableCell>
</TableRow>
</TableBody>
</Table>
)
}Examples
Wide table
In a narrow container the table scrolls sideways. Arrows and fades appear only on the side that has more to show.
| Region | City | CPU | Memory | Uptime | Latency | Version |
|---|---|---|---|---|---|---|
| eu-central-1 | Frankfurt | 8 vCPU | 32 GB | 99.99% | 41 ms | v2.14.0 |
| us-east-1 | Virginia | 16 vCPU | 64 GB | 99.95% | 88 ms | v2.14.0 |
| ap-south-1 | Mumbai | 4 vCPU | 16 GB | 99.90% | 132 ms | v2.13.2 |
<div className="max-w-sm">
<Table scrollLeftLabel="Scroll left" scrollRightLabel="Scroll right">
…
</Table>
</div>Selected row
data-state="selected" on TableRow highlights it, the same attribute shadcn/ui uses.
| Invoice | Status | Amount |
|---|---|---|
| INV001 | Paid | $250.00 |
| INV002 | Pending | $150.00 |
| INV003 | Unpaid | $350.00 |
<TableRow data-state="selected">…</TableRow>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| containerClassName | string | - | Classes for the scroll container, e.g. a max height (Table) |
| scrollLeftLabel | string | "Scroll left" | Accessible name of the left scroll button (Table) |
| scrollRightLabel | string | "Scroll right" | Accessible name of the right scroll button (Table) |
| data-state | "selected" | - | "selected" highlights the row (TableRow) |
| className | string | - | Additional CSS classes on any part |
| ...props | React.ComponentProps<…> | - | Every part accepts the attributes of its HTML element |