Table

Rows and columns of structured data. The wrapper scrolls rather than the page, so a wide table never forces horizontal scroll on the whole document.

src/components/ui/table.tsx

About

From the component's own source, where it was written.

Rows and columns of structured data.

The wrapper scrolls rather than the page, so a wide table never forces horizontal scroll on the whole document — the single most common table bug.

Install

npx astralyx-ui add table

Usage

import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from '@/components/ui/table'

<Table>
  <TableHeader>
    <TableRow><TableHead>Invoice</TableHead></TableRow>
  </TableHeader>
  <TableBody>
    <TableRow><TableCell>INV-001</TableCell></TableRow>
  </TableBody>
</Table>

Composer

Change the props and the source below follows.

InvoiceCustomerStatusAmount
INV-001Acme Corppaid$1,200.00
INV-002Globexpending$450.00
INV-003Initechfailed$980.00
INV-004Umbrellapaid$2,400.00
Total$5,030.00
Props
tsx
<Table>
  <TableHeader>…</TableHeader>
  <TableBody>…</TableBody>
  <TableFooter>…</TableFooter>
</Table>

Examples

With a footer

With a caption

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

Table

Rows and columns of structured data.

Extends ComponentProps<'table'>.

PropTypeDefaultDescription
containerClassNamestring—Styles the scrolling wrapper; className styles the <table> itself.

TableHeader

Map to thead, tbody and tfoot. The footer is tinted and divided.

Extends ComponentProps<'thead'>.

TableBody

Map to thead, tbody and tfoot. The footer is tinted and divided.

Extends ComponentProps<'tbody'>.

TableFooter

Map to thead, tbody and tfoot. The footer is tinted and divided.

Extends ComponentProps<'tfoot'>.

TableRow

Extends ComponentProps<'tr'>.

TableHead

Extends ComponentProps<'th'>.

TableCell

Extends ComponentProps<'td'>.

TableCaption

Rendered below the table, per caption-side.

Extends ComponentProps<'caption'>.

Behaviour

TopicDetailDescription
TableRow data-state"selected"Marks a row as selected, which tints its background.