# Table

> A static table built from column definitions.

- Category: [Data display](https://tarve.dev/docs.md#data)
- Import: `import { Table } from "@tarve/core";`
- Props type: `TableProps<T>` (generic)
- Source: [packages/core/src/extra-controls.ts:615](https://github.com/omarcosr/tarve/blob/main/packages/core/src/extra-controls.ts#L615)

## Usage

```tsx title="Table.tsx"
import { Table } from "@tarve/core";

const invoices = [
  { id: "INV001", status: "Paid", amount: "$250.00" },
  { id: "INV002", status: "Pending", amount: "$150.00" },
];

<Table
  style={{ width: 440 }}
  data={invoices}
  rowKey={(row) => row.id}
  columns={[
    { key: "id", header: "Invoice", accessor: "id" },
    { key: "status", header: "Status", accessor: "status" },
    { key: "amount", header: "Amount", accessor: "amount", align: "end" },
  ]}
/>
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `columns` (required) | `TableColumn<T>[]` | — |  |
| `data` (required) | `T[]` | — |  |
| `empty` | `Child` | `"No results."` |  |
| `onRowClick` | `(row: T, index: number) => void` | — |  |
| `rowKey` | `(row: T, index: number) => string \| number` | — |  |

## Common props

Shared by every component (descriptions: https://tarve.dev/docs.md#common-props): `children`, `class`, `className`, `highlight`, `id`, `key`, `motionFrom`, `onHighlight`, `onPaste`, `onPointerLeave`, `onPointerMove`, `onSize`, `onTransitionEnd`, `rovingGroup`, `style`.

## Types

```ts title="TableColumn"
interface TableColumn<T> {
  key: string;
  header: Child;
  accessor?: keyof T | ((row: T, index: number) => Child);
  render?: (row: T, index: number) => Child;
  width?: Style["width"];
  align?: Style["align"];
}
```

Previous: [VirtualList](https://tarve.dev/docs/components/VirtualList.md) · Next: [DataTable](https://tarve.dev/docs/components/DataTable.md)

---

Tarve v0.13.8 · HTML version: https://tarve.dev/docs/components/Table · Index for agents: https://tarve.dev/llms.txt
