Table
Installation
Add the component with the CLI.
npx shadcn@latest add @intentui/table
Composed components
When you install this component via the CLI, it automatically loads all composed components, so you don’t need to add them individually.
Manual installation
Install the dependencies, then copy the component source into your project.
npm install react-aria-components @heroicons/react cn
Anatomy
import {
Table,
TableBody,
TableCell,
TableColumn,
TableHeader,
TableRow,
} from "@/components/ui/table"<Table aria-label="Bands">
<TableHeader>
<TableColumn>#</TableColumn>
<TableColumn isRowHeader>Name</TableColumn>
</TableHeader>
<TableBody>
<TableRow>
<TableCell>1</TableCell>
<TableCell>Nirvana</TableCell>
</TableRow>
<TableRow>
<TableCell>2</TableCell>
<TableCell>The Beatles</TableCell>
</TableRow>
</TableBody>
</Table>Examples
Searchable
Use Autocomplete to filter table rows as users type.
This example is based on Devon Govett’s table filtering demo.
Expandable rows
Use expandable rows to show additional details below a row.
Bulk actions
Tables may require bulk actions for handling multiple entries at once.
Drag and drop
Similar to GridList, tables can also support drag and drop functionality.
Sorting
Tables can be made sortable. Activate sorting by clicking on a column header.
Resizable
Tables can be made resizable. To enable resizing, set the allowResize prop to true. And to make a column resizable, set the isResizable prop to true on the column.
Infinite scrolling
Load more items as users scroll with infinite scrolling.
Links
To create a clickable link within a table row, use the href prop.
<TableRow href='/collections/table-example'/>For client-side routing, React Aria recommends using the onAction event to handle navigation programmatically instead of passing an href prop.
This is because some collection items cannot be rendered as native elements due to HTML specification limitations.
Bleed
Use the bleed prop to make the table stretch to the edges of its container. This is especially useful in layouts like sidebars, where you want the table to align with the container's outer padding.
<Table bleed className="[--gutter:--spacing(6)] sm:[--gutter:--spacing(4)]" aria-label="..."/>With card
When placing a table inside a card, use bleed and set --gutter to var(--card-spacing) to align the table with the card's padding.
<Table bleed className="[--gutter:var(--card-spacing)]" aria-label="Users" />See the full demo at Sidebar 15.
Component API
Table
Table extends the React Aria Components <Table> component.
allowResizebooleanbleedbooleanfalseclassNamestringgridbooleanfalsestripedbooleanfalseTableBody
TableBody extends the React Aria Components <TableBody> component.
classNamestringTableCell
TableCell extends the React Aria Components <Cell> component.
classNamestringTableColumn
TableColumn extends the React Aria Components <Column> component.
classNamestringisResizablebooleanfalseTableHeader
TableHeader extends the React Aria Components <TableHeader> component.
classNamestringTableRow
TableRow extends the React Aria Components <Row> component.
classNamestringSee the React Aria for the full API reference.
