Table

Rows and columns, on native table elements.

Source
$npx @dinachi/cli@latest add table
Invoice 2048Due 1 Dec 2026
ItemQtyPriceAmount
Merino jumperCharcoal, M1 ×£118.00£118.00
Linen shirtSand, L2 ×£64.00£128.00
Wool scarfRust1 ×£38.00£38.00
Total£284.00
density
dividers
stack

Usage

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

export function Orders({ orders }: { orders: { id: string; customer: string; total: string }[] }) {
  return (
    <Table>
      <TableHeader>
        <TableRow>
          <TableHead>Order</TableHead>
          <TableHead>Customer</TableHead>
          <TableHead numeric>Total</TableHead>
        </TableRow>
      </TableHeader>
      <TableBody>
        {orders.map((o) => (
          <TableRow key={o.id}>
            <TableCell>{o.id}</TableCell>
            <TableCell>{o.customer}</TableCell>
            <TableCell numeric>{o.total}</TableCell>
          </TableRow>
        ))}
      </TableBody>
    </Table>
  )
}

Examples

Invoice 2048Due 1 Dec 2026
ItemQtyPriceAmount
Merino jumperCharcoal, M1 ×£118.00£118.00
Linen shirtSand, L2 ×£64.00£128.00
Wool scarfRust1 ×£38.00£38.00
Socks, 3 packGrey marl2 ×£15.00£30.00
Delivery£4.95
VAT included£53.16
Total£318.95
Numeric columns, a caption, and totals in the footer. Below 768px each line stacks.
import {
  Table,
  TableBody,
  TableCaption,
  TableCell,
  TableFooter,
  TableHead,
  TableHeader,
  TableRow,
} from '@/components/ui/table';

const lines = [
  { item: 'Merino jumper', variant: 'Charcoal, M', qty: 1, price: 118 },
  { item: 'Linen shirt', variant: 'Sand, L', qty: 2, price: 64 },
  { item: 'Wool scarf', variant: 'Rust', qty: 1, price: 38 },
  { item: 'Socks, 3 pack', variant: 'Grey marl', qty: 2, price: 15 },
];
const money = (n: number) => '£' + n.toLocaleString('en-GB', { minimumFractionDigits: 2 });

export function Example() {
  const total = lines.reduce((sum, l) => sum + l.qty * l.price, 0) + 4.95;
  return (
    <Table stack>
      <TableCaption>
        <span className="flex items-baseline justify-between">
          <span className="text-base font-semibold text-foreground">Invoice 2048</span>
          <span>Due 1 Dec 2026</span>
        </span>
      </TableCaption>
      <TableHeader>
        <TableRow>
          <TableHead>Item</TableHead>
          <TableHead numeric>Qty</TableHead>
          <TableHead numeric>Price</TableHead>
          <TableHead numeric>Amount</TableHead>
        </TableRow>
      </TableHeader>
      <TableBody>
        {lines.map((l) => (
          <TableRow key={l.item}>
            <TableCell stack="title">
              {l.item}
              <span className="block text-xs font-normal text-muted-foreground">{l.variant}</span>
            </TableCell>
            <TableCell numeric stack="meta">
              {l.qty}<span className="@lg:hidden"> ×</span>
            </TableCell>
            <TableCell numeric stack="meta">{money(l.price)}</TableCell>
            <TableCell numeric stack="value">{money(l.qty * l.price)}</TableCell>
          </TableRow>
        ))}
      </TableBody>
      <TableFooter>
        <TableRow>
          <TableCell colSpan={3} className="text-muted-foreground">Delivery</TableCell>
          <TableCell numeric>{money(4.95)}</TableCell>
        </TableRow>
        <TableRow>
          <TableCell colSpan={3} className="text-muted-foreground">VAT included</TableCell>
          <TableCell numeric className="text-muted-foreground">{money(total / 6)}</TableCell>
        </TableRow>
        <TableRow>
          <TableCell colSpan={3}>Total</TableCell>
          <TableCell numeric>{money(total)}</TableCell>
        </TableRow>
      </TableFooter>
    </Table>
  );
}

Notes

Phone and desktop

Without stack, a wide table scrolls sideways inside its container. With it, each row reads as a line item once the table is under 512px wide, wherever it sits: the title cell and the value cell on the first line, the meta cells under them, and the footer rows as label and figure. Give every body row one title and at most one value.

Sorting, selection and large data

Table is the markup and the look. Sorting, row selection and virtualised rows build on it in their own components.

API

density"comfortable" | "compact" = "comfortable"
Row height: 48px or 36px.
dividers"rows" | "none" = "rows"
Lines between body rows.
stackboolean = false
When the table is under 512px wide, each row becomes a block, its cells placed by their stack role.
containerClassNamestring
Classes for the scrolling container.
containerRefRef<HTMLDivElement>
The scrolling container, for a virtualiser or a scroll listener.

Accessibility

  • The parts are native table elements, so screen readers announce rows, columns and headers.
  • A stacked table sets the table roles on its parts, since browsers drop them once the parts stop displaying as a table.
  • Header cells are scoped to their column, and TableHead in a body row to its row.
  • Give the table a TableCaption or an aria-label so it is named.