Skip to content

Table

Desktop-grade data table for structured data display, with sorting, stripes, and custom cell rendering.

Basic Usage

Define columns with columns and pass data with data.

tsx
import { Table } from '@airo-ui/react'

const columns = [
  { label: 'Name', key: 'name', sortable: true },
  { label: 'Age', key: 'age', align: 'right' as const },
  { label: 'City', key: 'city' },
]

const data = [
  { id: 1, name: 'Alice', age: 28, city: 'New York' },
  { id: 2, name: 'Bob', age: 32, city: 'London' },
  { id: 3, name: 'Charlie', age: 24, city: 'Tokyo' },
  { id: 4, name: 'Diana', age: 35, city: 'Berlin' },
]

function Demo() {
  return <Table columns={columns} data={data} />
}

Striped

Set stripe for alternating row backgrounds.

tsx
<Table columns={columns} data={data} stripe />

Compact

Set size="sm" for compact mode with smaller row height.

tsx
<Table columns={columns} data={data} size="sm" />

Bordered

Set bordered to show column borders.

tsx
<Table columns={columns} data={data} bordered />

Custom Cells

Use the render function on column definitions for custom cell rendering.

tsx
const columns = [
  {
    label: 'Name',
    key: 'name',
    render: (value: unknown, row: any) => <strong>{value as string}</strong>,
  },
  {
    label: 'Age',
    key: 'age',
    align: 'right' as const,
    render: (value: unknown) => (
      <span style={{ color: 'var(--color-accent)' }}>{value as number} yo</span>
    ),
  },
  { label: 'City', key: 'city' },
]

<Table columns={columns} data={data} />

Loading

Set loading to show a loading overlay.

tsx
<Table columns={columns} data={data} loading />

Sorting

Set sortable: true on columns and listen to onSortChange.

tsx
<Table
  columns={columns}
  data={data}
  onSortChange={({ key, order }) => console.log(key, order)}
/>

API

Props

NameTypeDefaultDescription
columnsTableColumn[]RequiredColumn definitions
dataT[]RequiredData source
stripebooleanfalseStriped rows
borderedbooleanfalseColumn borders
size'sm' | 'md''md'Size
loadingbooleanfalseLoading state
rowKeystring'id'Row unique key field
onSortChange(payload: { key: string; order: 'asc' | 'desc' | '' }) => void--Sort change handler

TableColumn

PropertyTypeDescription
labelstringColumn header
keystringField name
sortablebooleanEnable sorting
widthstringColumn width
align'left' | 'center' | 'right'Text alignment
render(value: unknown, row: T, index: number) => ReactNodeCustom cell render function

Interaction

  • Click header to sort, three-state cycle (asc to desc to none)
  • Sort indicator icon changes color with state
  • Row hover highlight
  • Loading overlay on loading state
  • Empty data friendly message
  • Compact mode for dense desktop scenarios

MIT License