Table Components

Examples

Add `html` to render HTML elements in a table.

Product name Color Category Price Edit
Apple MacBook Pro 17" Sliver Laptop $2999 Edit
Microsoft Surface Pro White Laptop PC $1999 Edit
Magic Mouse 2 Black Accessories $99 Edit
<script>
import { Table, TableDefaultRow } from 'flowbite-svelte'
let itemEx = [
  ['Apple MacBook Pro 17"','Sliver','Laptop','$2999','<a href="/">Edit</a>'],
  ['Microsoft Surface Pro','White','Laptop PC','$1999','<a href="/">Edit</a>'],
  ['Magic Mouse 2','Black','Accessories','$99','<a href="/">Edit</a>']
]
let headerEx = [' Product name','Color','Category','Price','Edit']
</script>

<Table header={headerEx} {divClass} >
  <TableDefaultRow items={itemEx} html />
</Table>

Striped rows

Set `rowState` to striped to alternate background colors of every second tabel row.

Product name Color Category Price Edit
Apple MacBook Pro 17" Sliver Laptop $2999 Edit
Microsoft Surface Pro White Laptop PC $1999 Edit
Magic Mouse 2 Black Accessories $99 Edit
<Table header={headerEx} {divClass} >
  <TableDefaultRow items={itemEx} rowState="striped" html />
</Table>

Hover

Set `rowState` to hover to change the background color of a data row when hovering over the element with the cursor.

Product name Color Category Price Edit
Apple MacBook Pro 17" Sliver Laptop $2999 Edit
Microsoft Surface Pro White Laptop PC $1999 Edit
Magic Mouse 2 Black Accessories $99 Edit
<Table header={headerEx} {divClass} >
  <TableDefaultRow items={itemEx} rowState="hover" html />
</Table>
Product name Color Category Price Edit
Apple MacBook Pro 17" Sliver Laptop $2999 Edit
Microsoft Surface Pro White Laptop PC $1999 Edit
Magic Mouse 2 Black Accessories $99 Edit
<TableSearch menuItems={itemEx} header={headerEx} placeholder="Search by product name"/>

Props

The component has the following props, type, and default values. See types page for type information.

Table

Name Type Default
header Array<string>
divClass string 'relative overflow-x-auto shadow-md sm:rounded-lg'
tableClass string 'w-full text-sm text-left text-gray-500 dark:text-gray-400'
theadClass string 'text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400'

TableDefaultRow

Name Type Default
items Array<Array<string>>
html boolean false
rowState 'striped' | 'hover' | undefined undefined

TableSearch

Name Type Default
inputValue string ''
menuItems Array<Array<string>>
filteredItems Array<Array<string>> []
placeholder string 'Search'
header Array<string>
divClass string 'relative overflow-x-auto shadow-md sm:rounded-lg'
tableClass string 'w-full text-sm text-left text-gray-500 dark:text-gray-400'
theadClass string 'text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400'

References