Back to Shark UI

Table

docs/components/table

latest10.4 KB
Original Source

Sections

Components

Utilities

Forms

Hooks

Table

Copy Markdown

A responsive table component.

PreviewCode

A list of users in your workspace.| Name | Email | Role | Status | | --- | --- | --- | --- | | Alice Johnson | [email protected] | Admin | active | | Bruno Silva | [email protected] | Editor | invited | | Clara Mendes | [email protected] | Viewer | inactive | | David Park | [email protected] | Editor | active |

Installation#

CLIManual

pnpmbunnpmyarn

pnpm dlx shadcn@latest add @shark/table

Anatomy#

Table
├── TableCaption
├── TableHeader
│ └── TableRow
│ └── TableHead
├── TableBody
│ └── TableRow
│ └── TableCell
└── TableFooter
    └── TableRow
        └── TableCell

Usage#

import { 
  Table, 
  TableBody, 
  TableCaption, 
  TableCell, 
  TableHead, 
  TableHeader, 
  TableRow,
  TableFooter,
} from "@/components/ui/table";
<Table>
  <TableCaption />
  <TableHeader>
    <TableRow>
      <TableHead />
      <TableHead />
    </TableRow>
  </TableHeader>
  <TableBody>
    <TableRow>
      <TableCell />
      <TableCell />
    </TableRow>
  </TableBody>
  <TableFooter />
</Table>

Accessibility#

Always use a TableCaption to help assistive technologies announce what the table represents.

Use with the sr-only class to make the caption screen-reader only if you don't want to show it.

<Table>
  <TableCaption className="sr-only">
    Monthly revenue by product.
  </TableCaption>
</Table>

Examples#

Striped#

Use variant="striped" on Table for alternating row backgrounds.

PreviewCode

Users with alternating row backgrounds.| Name | Email | Role | Status | | --- | --- | --- | --- | | Alice Johnson | [email protected] | Admin | Active | | Bruno Silva | [email protected] | Editor | Invited | | Clara Mendes | [email protected] | Viewer | Inactive | | David Park | [email protected] | Editor | Active |

Use TableFooter for summary rows, totals, or notes.

PreviewCode

Order summary with footer totals.| Item | Qty | Unit price | Amount | | --- | --- | --- | --- | | Wireless mouse | 2 | $29.99 | $59.98 | | Mechanical keyboard | 1 | $149.99 | $149.99 | | USB-C hub | 3 | $45.00 | $135.00 | | Total | $379.47 |

With actions#

Add an actions column with buttons per row.

PreviewCode

Users with row actions (edit, delete).| Name | Email | Actions | | --- | --- | --- | | Alice Johnson | [email protected] | | | Bruno Silva | [email protected] | | | Clara Mendes | [email protected] | |

With action bar#

Use checkboxes for row selection and an action bar that appears when one or more rows are selected. See the action bar component.

PreviewCode

Orders with checkbox selection and action bar.|

| ID | Name | Status | Amount | | --- | --- | --- | --- | --- | |

| SO-01 | Macbook Pro 16 | progress | 245,12 $ | |

| SO-02 | Apple Watch Series 9 | transit | 122,18 $ | |

| SO-03 | AirPods Max | pending | 89,50 $ | |

| SO-04 | iPad Pro 13 | pending | 310,00 $ | |

| SO-05 | iPhone 15 Pro Max | transit | 156,75 $ |

With context menu#

Wrap each row with ContextMenuTrigger so right-clicking shows a context menu with row actions.

PreviewCode

Users with row context menu. Right-click a row to open the menu.| Name | Email | | --- | --- | | Alice Johnson | [email protected] | | Bruno Silva | [email protected] | | Clara Mendes | [email protected] |

Disable row hover#

Set isHoverable={false} on Table to disable the hover background on body rows.

PreviewCode

Table with row hover disabled (isHoverable=false).| Name | Email | | --- | --- | | Alice Johnson | [email protected] | | Bruno Silva | [email protected] | | Clara Mendes | [email protected] |

API Reference#

Table#

Scrollable wrapper around a native table. Supports striped and hover variants.

PropTypeDefault
variant`"plain""striped"`
isHoverablebooleantrue
classNamestring-
asChildbooleanfalse

TableHeader#

Table header row group.

PropTypeDefault
classNamestring-
asChildbooleanfalse

TableBody#

Table body row group.

PropTypeDefault
classNamestring-
asChildbooleanfalse

TableFooter#

Table footer row group for totals or summary rows.

PropTypeDefault
classNamestring-
asChildbooleanfalse

TableRow#

A single table row.

PropTypeDefault
classNamestring-
asChildbooleanfalse

TableHead#

Header cell for column titles.

PropTypeDefault
classNamestring-
asChildbooleanfalse

TableCell#

Data cell for body or footer rows.

PropTypeDefault
classNamestring-
asChildbooleanfalse

TableCaption#

Accessible caption describing the table. Use sr-only for screen-reader only.

PropTypeDefault
classNamestring-
asChildbooleanfalse

[

Previous page

Switch ](/docs/components/switch)[

Next page

Tabs ](/docs/components/tabs)

On This Page

InstallationAnatomyUsageAccessibilityExamplesStripedWith footerWith actionsWith action barWith context menuDisable row hoverAPI ReferenceTableTableHeaderTableBodyTableFooterTableRowTableHeadTableCellTableCaption