

<InteractiveDemo
  name="table"
  controls="[
  {
    type: 'enum',
    name: 'selectionMode',
    options: ['none', 'single', 'multiple'],
    defaultValue: 'none',
  },
]"
/>

## Installation [#installation]

<CodeBlockTabs defaultValue="npm">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="npm">
      npm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="pnpm">
      pnpm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="yarn">
      yarn
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="bun">
      bun
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="npm">
    ```bash
    npx shadcn@latest add @dotui/table
    ```
  </CodeBlockTab>

  <CodeBlockTab value="pnpm">
    ```bash
    pnpm dlx shadcn@latest add @dotui/table
    ```
  </CodeBlockTab>

  <CodeBlockTab value="yarn">
    ```bash
    yarn dlx shadcn@latest add @dotui/table
    ```
  </CodeBlockTab>

  <CodeBlockTab value="bun">
    ```bash
    bun x shadcn@latest add @dotui/table
    ```
  </CodeBlockTab>
</CodeBlockTabs>

## Usage [#usage]

Use tables to display data in rows and columns with support for selection, sorting, and more.

```tsx
import {
  Table,
  TableBody,
  TableCell,
  TableColumn,
  TableContainer,
  TableFooter,
  TableHeader,
  TableRow,
  TableVirtualizer,
} from '@/components/ui/table'
```

```tsx
<TableContainer>
  <Table aria-label="Files">
    <TableHeader>
      <TableColumn isRowHeader>Name</TableColumn>
      <TableColumn>Type</TableColumn>
      <TableColumn>Date Modified</TableColumn>
    </TableHeader>
    <TableBody>
      <TableRow>
        <TableCell>Games</TableCell>
        <TableCell>File folder</TableCell>
        <TableCell>6/7/2020</TableCell>
      </TableRow>
    </TableBody>
    <TableFooter>
      <TableRow>
        <TableCell colSpan={2}>Total</TableCell>
        <TableCell>1 item</TableCell>
      </TableRow>
    </TableFooter>
  </Table>
</TableContainer>
```

Use `TableContainer` to control the scroll region.

```tsx
<TableContainer className="max-h-80">
  <Table aria-label="Files">{/* ... */}</Table>
</TableContainer>
```

By default, `TableContainer` renders a plain `div` so the table uses native CSS auto layout. Set `resizable` to opt into React Aria's resizable table layout. In that mode, use `width`, `defaultWidth`, `minWidth`, and `maxWidth` on `TableColumn`.

```tsx
<TableContainer resizable>
  <Table aria-label="Files">
    <TableHeader>
      <TableColumn allowsResizing defaultWidth={240}>
        Name
      </TableColumn>
      <TableColumn allowsResizing defaultWidth={120}>
        Type
      </TableColumn>
    </TableHeader>
    <TableBody>{/* ... */}</TableBody>
  </Table>
</TableContainer>
```

Use `TableVirtualizer` for large collections. It uses the table layout exported by this component so row, cell, and selection column alignment stays consistent. Row and header heights default to the active density.

```tsx
<TableContainer className="h-80">
  <TableVirtualizer>
    <Table aria-label="Files">{/* ... */}</Table>
  </TableVirtualizer>
</TableContainer>
```

## Examples [#examples]

<Examples>
  <Example name="table/demos/basic" />

  <Example name="table/demos/invoices" />

  <Example name="table/demos/project-budget" />

  <Example name="table/demos/tasks" />

  <Example name="table/demos/large-list-virtualized" />

  <Example name="table/demos/async-loading" />

  <Example name="table/demos/controls" />

  <Example name="table/demos/dynamic-collection" />

  <Example name="table/demos/expandable-rows" />

  <Example name="table/demos/selection" />

  <Example name="table/demos/disallow-empty-selection" />

  <Example name="table/demos/disabled-rows" />

  <Example name="table/demos/links" />

  <Example name="table/demos/sorting" />

  <Example name="table/demos/column-resizing" />

  <Example name="table/demos/row-action" />

  <Example name="table/demos/static-row-action" />

  <Example name="table/demos/reordable" />

  <Example name="table/demos/empty-state" />

  <Example name="table/demos/uncontrolled" />

  <Example name="table/demos/controlled" />
</Examples>

## API Reference [#api-reference]

### TableContainer [#tablecontainer]

<Reference name="table-container" />

### Table [#table]

<Reference name="table" />

### TableHeader [#tableheader]

<Reference name="table-header" />

### TableColumn [#tablecolumn]

<Reference name="table-column" />

### TableBody [#tablebody]

<Reference name="table-body" />

### TableFooter [#tablefooter]

<Reference name="table-footer" />

### TableRow [#tablerow]

<Reference name="table-row" />

### TableCell [#tablecell]

<Reference name="table-cell" />

### TableLoadMore [#tableloadmore]

<Reference name="table-load-more" />

### TableDropIndicator [#tabledropindicator]

<Reference name="table-drop-indicator" />

### TableVirtualizer [#tablevirtualizer]

<Reference name="table-virtualizer" />
