Qwik table - Flowbite
Get started with the table component to show data such as text, numbers, images, and links using a structured set of data based on rows and columns based on Qwik
The table component is an important UI component that you can use to effectively show complex amounts of data in the form of numbers, text, images, buttons, and links inside a structured layout of rows and columns.
Use the custom Qwik components from Flowbite and the API reference of props to customize the table layout and content and the utility classes from Tailwind CSS to update the styles.
To start using the table component make sure you import it from flowbite-qwik :
import { Table } from "flowbite-qwik"
Default table
Use this example to show a responsive table component with table head and body featuring cells and rows on multiple levels by using the <Table> Qwik component and the children components such as <Table.Head>, <Table.Body>, <Table.Row> and <Table.Cell>.
import { component$ } from '@builder.io/qwik'
import { Link, Table } from 'flowbite-qwik'
export default component$(() => {
return (
<div class="overflow-x-auto">
<Table>
<Table.Head>
<Table.HeadCell>Product name</Table.HeadCell>
<Table.HeadCell>Color</Table.HeadCell>
<Table.HeadCell>Category</Table.HeadCell>
<Table.HeadCell>Price</Table.HeadCell>
<Table.HeadCell>
<span class="sr-only">Edit</span>
</Table.HeadCell>
</Table.Head>
<Table.Body class="divide-y">
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">{'Apple MacBook Pro 17"'}</Table.Cell>
<Table.Cell>Sliver</Table.Cell>
<Table.Cell>Laptop</Table.Cell>
<Table.Cell>$2999</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">Microsoft Surface Pro</Table.Cell>
<Table.Cell>White</Table.Cell>
<Table.Cell>Laptop PC</Table.Cell>
<Table.Cell>$1999</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">Magic Mouse 2</Table.Cell>
<Table.Cell>Black</Table.Cell>
<Table.Cell>Accessories</Table.Cell>
<Table.Cell>$99</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
</div>
)
})
Striped rows
Use the striped Qwik prop on the <Table> component to alternate the background of every second row of the table to increase contrast and readability.
import { component$ } from '@builder.io/qwik'
import { Link, Table } from 'flowbite-qwik'
export default component$(() => {
return (
<div class="overflow-x-auto">
<Table striped>
<Table.Head>
<Table.HeadCell>Product name</Table.HeadCell>
<Table.HeadCell>Color</Table.HeadCell>
<Table.HeadCell>Category</Table.HeadCell>
<Table.HeadCell>Price</Table.HeadCell>
<Table.HeadCell>
<span class="sr-only">Edit</span>
</Table.HeadCell>
</Table.Head>
<Table.Body class="divide-y">
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">{'Apple MacBook Pro 17"'}</Table.Cell>
<Table.Cell>Sliver</Table.Cell>
<Table.Cell>Laptop</Table.Cell>
<Table.Cell>$2999</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">Microsoft Surface Pro</Table.Cell>
<Table.Cell>White</Table.Cell>
<Table.Cell>Laptop PC</Table.Cell>
<Table.Cell>$1999</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">Magic Mouse 2</Table.Cell>
<Table.Cell>Black</Table.Cell>
<Table.Cell>Accessories</Table.Cell>
<Table.Cell>$99</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">Google Pixel Phone</Table.Cell>
<Table.Cell>Gray</Table.Cell>
<Table.Cell>Phone</Table.Cell>
<Table.Cell>$799</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">Apple Watch 5</Table.Cell>
<Table.Cell>Red</Table.Cell>
<Table.Cell>Wearables</Table.Cell>
<Table.Cell>$999</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
</div>
)
})
Hover state
Add the hoverable prop to the <Table> Qwik component to show a hover effect when moving the mouse over a table row. This also helps with readability.
import { component$ } from '@builder.io/qwik'
import { Link, Table } from 'flowbite-qwik'
export default component$(() => {
return (
<div class="overflow-x-auto">
<Table hoverable>
<Table.Head>
<Table.HeadCell>Product name</Table.HeadCell>
<Table.HeadCell>Color</Table.HeadCell>
<Table.HeadCell>Category</Table.HeadCell>
<Table.HeadCell>Price</Table.HeadCell>
<Table.HeadCell>
<span class="sr-only">Edit</span>
</Table.HeadCell>
</Table.Head>
<Table.Body class="divide-y">
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">{'Apple MacBook Pro 17"'}</Table.Cell>
<Table.Cell>Sliver</Table.Cell>
<Table.Cell>Laptop</Table.Cell>
<Table.Cell>$2999</Table.Cell>
<Table.Cell>
<Link href="#" class="text-cyan-600 dark:text-cyan-500">
Edit
</Link>
</Table.Cell>
</Table.Row>
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">Microsoft Surface Pro</Table.Cell>
<Table.Cell>White</Table.Cell>
<Table.Cell>Laptop PC</Table.Cell>
<Table.Cell>$1999</Table.Cell>
<Table.Cell>
<Link href="#" class="text-cyan-600 dark:text-cyan-500">
Edit
</Link>
</Table.Cell>
</Table.Row>
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">Magic Mouse 2</Table.Cell>
<Table.Cell>Black</Table.Cell>
<Table.Cell>Accessories</Table.Cell>
<Table.Cell>$99</Table.Cell>
<Table.Cell>
<Link href="#" class="text-cyan-600 dark:text-cyan-500">
Edit
</Link>
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
</div>
)
})
Table with checkboxes
Use this example to show multiple checkbox form elements for each table row that you can use when performing bulk actions
import { component$, useSignal } from '@builder.io/qwik'
import { Checkbox, Link, Table } from 'flowbite-qwik'
export default component$(() => {
const choice = useSignal(false)
return (
<div class="overflow-x-auto">
<Table hoverable>
<Table.Head>
<Table.HeadCell class="p-4">
<Checkbox bind:checked={choice} />
</Table.HeadCell>
<Table.HeadCell>Product name</Table.HeadCell>
<Table.HeadCell>Color</Table.HeadCell>
<Table.HeadCell>Category</Table.HeadCell>
<Table.HeadCell>Price</Table.HeadCell>
<Table.HeadCell>
<span class="sr-only">Edit</span>
</Table.HeadCell>
</Table.Head>
<Table.Body class="divide-y">
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="p-4">
<Checkbox bind:checked={choice} />
</Table.Cell>
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">{'Apple MacBook Pro 17"'}</Table.Cell>
<Table.Cell>Sliver</Table.Cell>
<Table.Cell>Laptop</Table.Cell>
<Table.Cell>$2999</Table.Cell>
<Table.Cell>
<Link href="#" class="text-gray-9000">
Edit
</Link>
</Table.Cell>
</Table.Row>
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="p-4">
<Checkbox bind:checked={choice} />
</Table.Cell>
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">Microsoft Surface Pro</Table.Cell>
<Table.Cell>White</Table.Cell>
<Table.Cell>Laptop PC</Table.Cell>
<Table.Cell>$1999</Table.Cell>
<Table.Cell>
<Link href="#" class="text-gray-9000">
Edit
</Link>
</Table.Cell>
</Table.Row>
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="p-4">
<Checkbox bind:checked={choice} />
</Table.Cell>
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">Magic Mouse 2</Table.Cell>
<Table.Cell>Black</Table.Cell>
<Table.Cell>Accessories</Table.Cell>
<Table.Cell>$99</Table.Cell>
<Table.Cell>
<Link href="#" class="text-gray-9000">
Edit
</Link>
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
</div>
)
})
Table multiple
Use this example to show multiple tables on the same page
import { component$ } from '@builder.io/qwik'
import { Link, Table } from 'flowbite-qwik'
export default component$(() => {
return (
<div class="flex flex-col gap-8">
<div class="overflow-x-auto">
<Table>
<Table.Head>
<Table.HeadCell>Product name</Table.HeadCell>
<Table.HeadCell>Color</Table.HeadCell>
<Table.HeadCell>Category</Table.HeadCell>
<Table.HeadCell>Price</Table.HeadCell>
<Table.HeadCell>
<span class="sr-only">Edit</span>
</Table.HeadCell>
</Table.Head>
<Table.Body class="divide-y">
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">{'Apple MacBook Pro 17"'}</Table.Cell>
<Table.Cell>Sliver</Table.Cell>
<Table.Cell>Laptop</Table.Cell>
<Table.Cell>$2999</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">Microsoft Surface Pro</Table.Cell>
<Table.Cell>White</Table.Cell>
<Table.Cell>Laptop PC</Table.Cell>
<Table.Cell>$1999</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">Magic Mouse 2</Table.Cell>
<Table.Cell>Black</Table.Cell>
<Table.Cell>Accessories</Table.Cell>
<Table.Cell>$99</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
</div>
<div class="overflow-x-auto">
<Table hoverable>
<Table.Head>
<Table.HeadCell>Product name</Table.HeadCell>
<Table.HeadCell>Color</Table.HeadCell>
<Table.HeadCell>Category</Table.HeadCell>
<Table.HeadCell>Price</Table.HeadCell>
<Table.HeadCell>
<span class="sr-only">Edit</span>
</Table.HeadCell>
</Table.Head>
<Table.Body class="divide-y">
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">{'Apple MacBook Pro 17"'}</Table.Cell>
<Table.Cell>Sliver</Table.Cell>
<Table.Cell>Laptop</Table.Cell>
<Table.Cell>$2999</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">Microsoft Surface Pro</Table.Cell>
<Table.Cell>White</Table.Cell>
<Table.Cell>Laptop PC</Table.Cell>
<Table.Cell>$1999</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">Magic Mouse 2</Table.Cell>
<Table.Cell>Black</Table.Cell>
<Table.Cell>Accessories</Table.Cell>
<Table.Cell>$99</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
</div>
</div>
)
})
Table theme
Use theme to customize styles of table
import { component$ } from '@builder.io/qwik'
import { Link, Table } from 'flowbite-qwik'
export default component$(() => {
return (
<div class="overflow-x-auto">
<Table theme={{ cell: 'py-2' }}>
<Table.Head>
<Table.HeadCell>Product name</Table.HeadCell>
<Table.HeadCell>Color</Table.HeadCell>
<Table.HeadCell>Category</Table.HeadCell>
<Table.HeadCell>Price</Table.HeadCell>
<Table.HeadCell>
<span class="sr-only">Edit</span>
</Table.HeadCell>
</Table.Head>
<Table.Body class="divide-y">
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">{'Apple MacBook Pro 17"'}</Table.Cell>
<Table.Cell>Sliver</Table.Cell>
<Table.Cell>Laptop</Table.Cell>
<Table.Cell>$2999</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">Microsoft Surface Pro</Table.Cell>
<Table.Cell>White</Table.Cell>
<Table.Cell>Laptop PC</Table.Cell>
<Table.Cell>$1999</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell class="whitespace-nowrap font-medium text-gray-900 dark:text-white">Magic Mouse 2</Table.Cell>
<Table.Cell>Black</Table.Cell>
<Table.Cell>Accessories</Table.Cell>
<Table.Cell>$99</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
</div>
)
})
Dynamic table
Use this example to show a responsive table component with table head and body featuring cells and rows on multiple levels by using the <Table> Qwik component and the children components such as <Table.Head>, <Table.Body>, <Table.Row> and <Table.Cell>.
import { $, component$, useStore } from '@builder.io/qwik'
import { Button, Link, Table } from 'flowbite-qwik'
export default component$(() => {
const data = useStore([
{
id: 1,
name: 'Apple MacBook Pro 17"',
color: 'Sliver',
category: 'Laptop',
price: '$2999',
},
{
id: 2,
name: 'Microsoft Surface Pro',
color: 'White',
category: 'Laptop PC',
price: '$1999',
},
{
id: 3,
name: 'Magic Mouse 2',
color: 'Black',
category: 'Accessories',
price: '$99',
},
])
const hadRow$ = $(() => {
data.push({
id: 4,
name: 'Apple MacBook Pro 16"',
color: 'Sliver',
category: 'Laptop',
price: '$1999',
})
})
return (
<div class="flex flex-col gap-2 overflow-x-auto">
<Button onClick$={hadRow$}>Add row</Button>
<Table>
<Table.Head>
<Table.HeadCell>Product name</Table.HeadCell>
<Table.HeadCell>Color</Table.HeadCell>
<Table.HeadCell>Category</Table.HeadCell>
<Table.HeadCell>Price</Table.HeadCell>
<Table.HeadCell>
<span class="sr-only">Edit</span>
</Table.HeadCell>
</Table.Head>
<Table.Body class="divide-y">
{data.map((item) => (
<Table.Row class="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.color}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell>{item.price}</Table.Cell>
<Table.Cell>
<Link href="#">Edit</Link>
</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table>
</div>
)
})