Table Components
Default table
Use the following example of a responsive table component to show multiple rows and columns of text data.
<Table>
<TableHead>
<TableHeadCell>Product name</TableHeadCell>
<TableHeadCell>Color</TableHeadCell>
<TableHeadCell>Category</TableHeadCell>
<TableHeadCell>Price</TableHeadCell>
<TableHeadCell>
<span class="sr-only"> Edit </span>
</TableHeadCell>
</TableHead>
<TableBody class="divide-y">
<TableBodyRow>
<TableBodyCell>
Apple MacBook Pro 17"
</TableBodyCell>
<TableBodyCell>Sliver</TableBodyCell>
<TableBodyCell>Laptop</TableBodyCell>
<TableBodyCell>$2999</TableBodyCell>
<TableBodyCell>
<a href="/tables" class="font-medium text-blue-600 hover:underline dark:text-blue-500"> Edit </a>
</TableBodyCell>
</TableBodyRow>
<TableBodyRow>
<TableBodyCell>
Microsoft Surface Pro
</TableBodyCell>
<TableBodyCell>White</TableBodyCell>
<TableBodyCell>Laptop PC</TableBodyCell>
<TableBodyCell>$1999</TableBodyCell>
<TableBodyCell>
<a href="/tables" class="font-medium text-blue-600 hover:underline dark:text-blue-500"> Edit </a>
</TableBodyCell>
</TableBodyRow>
<TableBodyRow>
<TableBodyCell>
Magic Mouse 2
</TableBodyCell>
<TableBodyCell>Black</TableBodyCell>
<TableBodyCell>Accessories</TableBodyCell>
<TableBodyCell>$99</TableBodyCell>
<TableBodyCell>
<a href="/tables" class="font-medium text-blue-600 hover:underline dark:text-blue-500"> Edit </a>
</TableBodyCell>
</TableBodyRow>
</TableBody>
</Table>
Striped rows
Set the `stiped` prop to `true` to alternate background colors of every second tabel row.
<Table striped={true}>
<TableHead>
<TableHeadCell>Product name</TableHeadCell>
<TableHeadCell>Color</TableHeadCell>
<TableHeadCell>Category</TableHeadCell>
<TableHeadCell>Price</TableHeadCell>
<TableHeadCell>
<span class="sr-only"> Edit </span>
</TableHeadCell>
</TableHead>
<TableBody class="divide-y">
<TableBodyRow>
<TableBodyCell>
Apple MacBook Pro 17"
</TableBodyCell>
<TableBodyCell>Sliver</TableBodyCell>
<TableBodyCell>Laptop</TableBodyCell>
<TableBodyCell>$2999</TableBodyCell>
<TableBodyCell>
<a href="/tables" class="font-medium text-blue-600 hover:underline dark:text-blue-500"> Edit </a>
</TableBodyCell>
</TableBodyRow>
<TableBodyRow>
<TableBodyCell>
Microsoft Surface Pro
</TableBodyCell>
<TableBodyCell>White</TableBodyCell>
<TableBodyCell>Laptop PC</TableBodyCell>
<TableBodyCell>$1999</TableBodyCell>
<TableBodyCell>
<a href="/tables" class="font-medium text-blue-600 hover:underline dark:text-blue-500"> Edit </a>
</TableBodyCell>
</TableBodyRow>
<TableBodyRow>
<TableBodyCell>
Magic Mouse 2
</TableBodyCell>
<TableBodyCell>Black</TableBodyCell>
<TableBodyCell>Accessories</TableBodyCell>
<TableBodyCell>$99</TableBodyCell>
<TableBodyCell>
<a href="/tables" class="font-medium text-blue-600 hover:underline dark:text-blue-500"> Edit </a>
</TableBodyCell>
</TableBodyRow>
<TableBodyRow>
<TableBodyCell>
Google Pixel Phone
</TableBodyCell>
<TableBodyCell>Gray</TableBodyCell>
<TableBodyCell>Phone</TableBodyCell>
<TableBodyCell>$799</TableBodyCell>
<TableBodyCell>
<a href="/tables" class="font-medium text-blue-600 hover:underline dark:text-blue-500"> Edit </a>
</TableBodyCell>
</TableBodyRow>
<TableBodyRow>
<TableBodyCell>
Apple Watch 5
</TableBodyCell>
<TableBodyCell>Red</TableBodyCell>
<TableBodyCell>Wearables</TableBodyCell>
<TableBodyCell>$999</TableBodyCell>
<TableBodyCell>
<a href="/tables" class="font-medium text-blue-600 hover:underline dark:text-blue-500"> Edit </a>
</TableBodyCell>
</TableBodyRow>
</TableBody>
</Table>
Hover state
Set `hoverable` to `true` to change the background color of a data row when hovering over the element with the cursor.
<Table hoverable={true}>
<TableHead>
<TableHeadCell>Product name</TableHeadCell>
<TableHeadCell>Color</TableHeadCell>
<TableHeadCell>Category</TableHeadCell>
<TableHeadCell>Price</TableHeadCell>
<TableHeadCell>
<span class="sr-only"> Edit </span>
</TableHeadCell>
</TableHead>
<TableBody class="divide-y">
<TableBodyRow>
<TableBodyCell>
Apple MacBook Pro 17"
</TableBodyCell>
<TableBodyCell>Sliver</TableBodyCell>
<TableBodyCell>Laptop</TableBodyCell>
<TableBodyCell>$2999</TableBodyCell>
<TableBodyCell>
<a href="/tables" class="font-medium text-blue-600 hover:underline dark:text-blue-500"> Edit </a>
</TableBodyCell>
</TableBodyRow>
<TableBodyRow>
<TableBodyCell>
Microsoft Surface Pro
</TableBodyCell>
<TableBodyCell>White</TableBodyCell>
<TableBodyCell>Laptop PC</TableBodyCell>
<TableBodyCell>$1999</TableBodyCell>
<TableBodyCell>
<a href="/tables" class="font-medium text-blue-600 hover:underline dark:text-blue-500"> Edit </a>
</TableBodyCell>
</TableBodyRow>
<TableBodyRow>
<TableBodyCell>
Magic Mouse 2
</TableBodyCell>
<TableBodyCell>Black</TableBodyCell>
<TableBodyCell>Accessories</TableBodyCell>
<TableBodyCell>$99</TableBodyCell>
<TableBodyCell>
<a href="/tables" class="font-medium text-blue-600 hover:underline dark:text-blue-500"> Edit </a>
</TableBodyCell>
</TableBodyRow>
</TableBody>
</Table>
Checkbox
Checkboxes can be used inside table data rows to select multiple data sets and apply a bulk action.
<Table hoverable={true}>
<TableHead>
<TableHeadCell class="!p-4">
<Checkbox />
</TableHeadCell>
<TableHeadCell>Product name</TableHeadCell>
<TableHeadCell>Color</TableHeadCell>
<TableHeadCell>Category</TableHeadCell>
<TableHeadCell>Price</TableHeadCell>
<TableHeadCell>
<span class="sr-only"> Edit </span>
</TableHeadCell>
</TableHead>
<TableBody class="divide-y">
<TableBodyRow>
<TableBodyCell class="!p-4">
<Checkbox />
</TableBodyCell>
<TableBodyCell>
Apple MacBook Pro 17"
</TableBodyCell>
<TableBodyCell>Sliver</TableBodyCell>
<TableBodyCell>Laptop</TableBodyCell>
<TableBodyCell>$2999</TableBodyCell>
<TableBodyCell>
<a href="/tables" class="font-medium text-blue-600 hover:underline dark:text-blue-500"> Edit </a>
</TableBodyCell>
</TableBodyRow>
<TableBodyRow>
<TableBodyCell class="!p-4">
<Checkbox />
</TableBodyCell>
<TableBodyCell>
Microsoft Surface Pro
</TableBodyCell>
<TableBodyCell>White</TableBodyCell>
<TableBodyCell>Laptop PC</TableBodyCell>
<TableBodyCell>$1999</TableBodyCell>
<TableBodyCell>
<a href="/tables" class="font-medium text-blue-600 hover:underline dark:text-blue-500"> Edit </a>
</TableBodyCell>
</TableBodyRow>
<TableBodyRow>
<TableBodyCell class="!p-4">
<Checkbox />
</TableBodyCell>
<TableBodyCell>
Magic Mouse 2
</TableBodyCell>
<TableBodyCell>Black</TableBodyCell>
<TableBodyCell>Accessories</TableBodyCell>
<TableBodyCell>$99</TableBodyCell>
<TableBodyCell>
<a href="/tables" class="font-medium text-blue-600 hover:underline dark:text-blue-500"> Edit </a>
</TableBodyCell>
</TableBodyRow>
</TableBody>
</Table>
Search input
<TableSearch hoverable={true}>
<TableHead>
<TableHeadCell>Product name</TableHeadCell>
<TableHeadCell>Color</TableHeadCell>
<TableHeadCell>Category</TableHeadCell>
<TableHeadCell>Price</TableHeadCell>
<TableHeadCell>
<span class="sr-only"> Edit </span>
</TableHeadCell>
</TableHead>
<TableBody class="divide-y">
<TableBodyRow>
<TableBodyCell>
Apple MacBook Pro 17"
</TableBodyCell>
<TableBodyCell>Sliver</TableBodyCell>
<TableBodyCell>Laptop</TableBodyCell>
<TableBodyCell>$2999</TableBodyCell>
<TableBodyCell>
<a href="/tables" class="font-medium text-blue-600 hover:underline dark:text-blue-500"> Edit </a>
</TableBodyCell>
</TableBodyRow>
<TableBodyRow>
<TableBodyCell>
Microsoft Surface Pro
</TableBodyCell>
<TableBodyCell>White</TableBodyCell>
<TableBodyCell>Laptop PC</TableBodyCell>
<TableBodyCell>$1999</TableBodyCell>
<TableBodyCell>
<a href="/tables" class="font-medium text-blue-600 hover:underline dark:text-blue-500"> Edit </a>
</TableBodyCell>
</TableBodyRow>
<TableBodyRow>
<TableBodyCell>
Magic Mouse 2
</TableBodyCell>
<TableBodyCell>Black</TableBodyCell>
<TableBodyCell>Accessories</TableBodyCell>
<TableBodyCell>$99</TableBodyCell>
<TableBodyCell>
<a href="/tables" class="font-medium text-blue-600 hover:underline dark:text-blue-500"> Edit </a>
</TableBodyCell>
</TableBodyRow>
</TableBody>
</TableSearch>
Props
The component has the following props, type, and default values. See types page for type information.
Table
Name | Type | Default |
---|---|---|
divClass | string | 'relative overflow-x-auto shadow-md sm:rounded-lg' |
striped | boolean | false |
hoverable | boolean | false |
TableBodyCell
Name | Type | Default |
---|---|---|
tdClass | string | 'px-6 py-4 whitespace-nowrap font-medium text-gray-900 dark:text-white' |
TableBodyRow
Name | Type | Default |
---|---|---|
trClass | string | 'bg-white dark:border-gray-700 dark:bg-gray-800' |
TableSearch
Name | Type | Default |
---|---|---|
divClass | string | 'relative overflow-x-auto shadow-md sm:rounded-lg' |
inputValue | string | '' |
striped | boolean | false |
hoverable | boolean | false |
menuItems | Array<Array<string>> | |
filteredItems | Array<Array<string>> | [] |
placeholder | string | 'Search' |