gridland
Components

Table

A data table with automatic column sizing and compound sub-components

A data table with automatic column detection, horizontal-only separators, and a compound sub-component API for full layout control.

Table
?

Run demo

Terminal
bunx @gridland/demo table
Terminal
curl -fsSL https://raw.githubusercontent.com/thoughtfulllc/gridland/main/scripts/run-demo.sh | bash -s table

Installation

Terminal
bunx create-gridland add table

Usage

import { Table } from "@/components/ui/table"
<Table
  data={[
    { name: "Alice", role: "Engineer", status: "Active" },
    { name: "Bob", role: "Designer", status: "Active" },
    { name: "Charlie", role: "PM", status: "Away" },
  ]}
/>

Examples

Custom Columns

Select and order which columns to display.

Custom columns
<Table
  data={[
    { name: "Alice", age: 30, role: "Engineer" },
    { name: "Bob", age: 25, role: "Designer" },
  ]}
  columns={["name", "role"]}
/>

Custom Colors

Override the default header and separator colors.

Custom colors
<Table
  data={[
    { name: "Alice", role: "Engineer" },
    { name: "Bob", role: "Designer" },
  ]}
  headerColor="cyan"
  borderColor="#5e81ac"
/>

Compound API

For full layout control, use TableRoot with sub-components.

Compound table
import {
  TableRoot,
  TableHeader,
  TableBody,
  TableFooter,
  TableRow,
  TableHead,
  TableCell,
  TableCaption,
} from "@/components/ui/table"

<TableRoot>
  <TableCaption>A list of your recent invoices.</TableCaption>
  <TableHeader>
    <TableRow>
      <TableHead>Invoice</TableHead>
      <TableHead>Status</TableHead>
      <TableHead>Amount</TableHead>
    </TableRow>
  </TableHeader>
  <TableBody>
    <TableRow>
      <TableCell>INV001</TableCell>
      <TableCell>Paid</TableCell>
      <TableCell>$250.00</TableCell>
    </TableRow>
  </TableBody>
  <TableFooter>
    <TableRow>
      <TableCell>Total</TableCell>
      <TableCell></TableCell>
      <TableCell>$250.00</TableCell>
    </TableRow>
  </TableFooter>
</TableRoot>

Cell Alignment

Right-align or center-align individual cells using the align prop.

Right-aligned prices
<TableRoot>
  <TableHeader>
    <TableRow>
      <TableHead>Item</TableHead>
      <TableHead align="right">Price</TableHead>
    </TableRow>
  </TableHeader>
  <TableBody>
    <TableRow>
      <TableCell>Widget</TableCell>
      <TableCell align="right">$10.00</TableCell>
    </TableRow>
    <TableRow>
      <TableCell>Gadget</TableCell>
      <TableCell align="right">$25.00</TableCell>
    </TableRow>
  </TableBody>
</TableRoot>

Cell Color

Override the text color for individual cells.

Colored status cells
<TableRoot>
  <TableHeader>
    <TableRow>
      <TableHead>Name</TableHead>
      <TableHead>Status</TableHead>
    </TableRow>
  </TableHeader>
  <TableBody>
    <TableRow>
      <TableCell>Alice</TableCell>
      <TableCell color="green">Active</TableCell>
    </TableRow>
    <TableRow>
      <TableCell>Bob</TableCell>
      <TableCell color="red">Inactive</TableCell>
    </TableRow>
  </TableBody>
</TableRoot>

Column Span

Use colSpan to span a cell across multiple columns.

Footer with colSpan
<TableRoot>
  <TableHeader>
    <TableRow>
      <TableHead>Item</TableHead>
      <TableHead>Qty</TableHead>
      <TableHead align="right">Price</TableHead>
    </TableRow>
  </TableHeader>
  <TableBody>
    <TableRow>
      <TableCell>Widget</TableCell>
      <TableCell>2</TableCell>
      <TableCell align="right">$20.00</TableCell>
    </TableRow>
  </TableBody>
  <TableFooter>
    <TableRow>
      <TableCell colSpan={2}>Total</TableCell>
      <TableCell align="right">$20.00</TableCell>
    </TableRow>
  </TableFooter>
</TableRoot>

Compound Components

ComponentDescription
TableRootCompound root — computes column widths and provides layout context
TableHeaderWraps header rows with a solid separator below
TableBodyWraps body rows with dimmed separators between them
TableFooterWraps footer rows with a solid separator above
TableRowReads TableHead/TableCell children and renders a styled row
TableHeadHeader cell — does not render on its own
TableCellBody cell — does not render on its own
TableCaptionMuted caption text below the table

API Reference

Table

Data-driven table with automatic column detection.

PropTypeDefaultDescription
dataT[]-Array of data objects to display
columns(keyof T)[]-Keys to display as columns (auto-detected if omitted)
paddingnumber1Cell padding in characters
headerColorstringtheme.foregroundHeader text color
borderColorstringtheme.mutedSeparator line color

TableRoot

Compound root that computes column widths from the component tree.

PropTypeDefaultDescription
childrenReactNode-Table sub-components
paddingnumber1Cell padding in characters
headerColorstringtheme.foregroundHeader text color
borderColorstringtheme.mutedSeparator line color

TableHeader

PropTypeDefaultDescription
childrenReactNode-One or more TableRow components

TableBody

PropTypeDefaultDescription
childrenReactNode-One or more TableRow components

TableFooter

PropTypeDefaultDescription
childrenReactNode-One or more TableRow components

TableRow

PropTypeDefaultDescription
childrenReactNode-TableHead or TableCell components

TableHead

PropTypeDefaultDescription
childrenReactNode-Cell content (typically a string)
align"left" | "right" | "center""left"Text alignment within the cell
colorstring-Override text color for this header cell
colSpannumber1Number of columns this cell should span

TableCell

PropTypeDefaultDescription
childrenReactNode-Cell content (typically a string)
align"left" | "right" | "center""left"Text alignment within the cell
colorstring-Override text color for this body cell
colSpannumber1Number of columns this cell should span

TableCaption

PropTypeDefaultDescription
childrenReactNode-Caption text