Table
A robust set of components for building responsive, accessible, and customizable data tables. Includes support for sorting, resizing, pagination, borders, and more.
Table
Use the table primitives to compose standard HTML tables with built-in styling.
| Name | Title | Email |
|---|---|---|
| John Doe | Frontend Engineer | john@example.com |
| Jane Smith | Product Manager | jane@example.com |
---
import Table from '@/components/data-display/Table.astro';
import TableHead from '@/components/data-display/TableHead.astro';
import TableBody from '@/components/data-display/TableBody.astro';
import TableRow from '@/components/data-display/TableRow.astro';
import TableHeadCell from '@/components/data-display/TableHeadCell.astro';
import TableCell from '@/components/data-display/TableCell.astro';
---
<Table>
<TableHead>
<TableRow>
<TableHeadCell>Name</TableHeadCell>
<TableHeadCell>Title</TableHeadCell>
<TableHeadCell>Email</TableHeadCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>John Doe</TableCell>
<TableCell>Frontend Engineer</TableCell>
<TableCell>john@example.com</TableCell>
</TableRow>
<TableRow>
<TableCell>Jane Smith</TableCell>
<TableCell>Product Manager</TableCell>
<TableCell>jane@example.com</TableCell>
</TableRow>
</TableBody>
</Table> Advanced Table Features
Tables can include resizable columns, sortable headers, sticky states, nested UI components (avatars, tags, buttons), and tree structures.
| | Employee | Status | Role | Actions |
|---|---|---|---|---|
| Alice Cooper alice@company.com | Active | Designer | | |
| Bob Builder bob@company.com | On Leave | Junior Designer | | |
| Charlie Davis charlie@company.com | Offline | Developer | |
<Table maxHeight striped>
<TableHead>
<TableRow>
<TableHeadCell sticky align='center' class='w-12'
><Checkbox /></TableHeadCell
>
<TableHeadCell sticky sortable sortDirection='asc' resizable
>Employee</TableHeadCell
>
<TableHeadCell sticky sortable resizable>Status</TableHeadCell>
<TableHeadCell sticky>Role</TableHeadCell>
<TableHeadCell sticky align='right'>Actions</TableHeadCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow data-state='selected'>
<TableCell align='center'><Checkbox checked /></TableCell>
<TableCell>
<div class='flex items-center gap-3'>
<Avatar
src='https://i.pravatar.cc/150?u=a042581f4e29026024d'
/>
<div class='flex flex-col'>
<span class='font-medium text-zinc-900 dark:text-zinc-100'
>Alice Cooper</span
>
<span class='text-xs text-zinc-500'
>alice@company.com</span
>
</div>
</div>
</TableCell>
<TableCell><Tag>Active</Tag></TableCell>
<TableCell>Designer</TableCell>
<TableCell align='right'>
<Dropdown>
<Button
variant='ghost'
iconOnly
class='h-8 w-8'
slot='trigger'
><Icon name='MoveHorizontal' /></Button
>
<DropdownItem>Edit</DropdownItem>
<DropdownItem intent='danger'>Delete</DropdownItem>
</Dropdown>
</TableCell>
</TableRow>
<TableRow>
<TableCell align='center'><Checkbox /></TableCell>
<TableCell>
<div
class='flex items-center gap-3 pl-6 border-l-2 border-zinc-200 dark:border-zinc-800 ml-3'>
<Icon
name='CornerDownRight'
class='h-4 w-4 text-zinc-400'
/>
<Avatar
src='https://i.pravatar.cc/150?u=a042581f4e29026024e'
/>
<div class='flex flex-col'>
<span class='font-medium text-zinc-900 dark:text-zinc-100'
>Bob Builder</span
>
<span class='text-xs text-zinc-500'>bob@company.com</span>
</div>
</div>
</TableCell>
<TableCell><Tag>On Leave</Tag></TableCell>
<TableCell>Junior Designer</TableCell>
<TableCell align='right'>
<Dropdown>
<Button
variant='ghost'
iconOnly
class='h-8 w-8'
slot='trigger'
><Icon name='MoveHorizontal' /></Button
>
<DropdownItem>Edit</DropdownItem>
<DropdownItem intent='danger'>Delete</DropdownItem>
</Dropdown>
</TableCell>
</TableRow>
<TableRow>
<TableCell align='center'><Checkbox /></TableCell>
<TableCell>
<div class='flex items-center gap-3'>
<Avatar
src='https://i.pravatar.cc/150?u=a042581f4e29026024f'
/>
<div class='flex flex-col'>
<span class='font-medium text-zinc-900 dark:text-zinc-100'
>Charlie Davis</span
>
<span class='text-xs text-zinc-500'
>charlie@company.com</span
>
</div>
</div>
</TableCell>
<TableCell><Tag>Offline</Tag></TableCell>
<TableCell>Developer</TableCell>
<TableCell align='right'>
<Dropdown>
<Button
variant='ghost'
iconOnly
class='h-8 w-8'
slot='trigger'
><Icon name='MoveHorizontal' /></Button
>
<DropdownItem>Edit</DropdownItem>
<DropdownItem intent='danger'>Delete</DropdownItem>
</Dropdown>
</TableCell>
</TableRow>
</TableBody>
</Table>
<div class='flex items-center justify-between mt-4'>
<span class='text-sm text-zinc-500'
>Showing 1 to 3 of 24 results</span
>
<Pagination totalPages={5} currentPage={1} />
</div></TableHeadCell>
<TableHeadCell sticky sortable sortDirection="asc" resizable>Employee</TableHeadCell>
<TableHeadCell sticky sortable resizable>Status</TableHeadCell>
<TableHeadCell sticky>Role</TableHeadCell>
<TableHeadCell sticky align="right">Actions</TableHeadCell>
</TableRow>
</TableHead>
<TableBody>
<!-- Use data-state="selected" to highlight a row -->
<TableRow data-state="selected">
<TableCell align="center"><Checkbox checked /></TableCell>
<TableCell>
<div class="flex items-center gap-3">
<Avatar fallback="AC" alt="Alice Cooper" size="sm" />
<div class="flex flex-col">
<span class="font-medium text-zinc-900 dark:text-zinc-100">Alice Cooper</span>
<span class="text-xs text-zinc-500">alice@company.com</span>
</div>
</div>
</TableCell>
<TableCell><Tag>Active</Tag></TableCell>
<TableCell>Designer</TableCell>
<TableCell align="right">
<Dropdown>
<Button variant="ghost" size="icon" class="h-8 w-8" slot="trigger"><Icon name="MoveHorizontal" /></Button>
<DropdownItem>Edit</DropdownItem>
</Dropdown>
</TableCell>
</TableRow>
<!-- Indented / Tree Row Example -->
<TableRow>
<TableCell align="center"><Checkbox /></TableCell>
<TableCell>
<div class="flex items-center gap-3 pl-6 border-l-2 border-zinc-200 ml-3">
<Icon name="CornerDownRight" class="h-4 w-4 text-zinc-400" />
<Avatar fallback="BB" alt="Bob Builder" size="sm" />
<div class="flex flex-col">
<span class="font-medium">Bob Builder</span>
</div>
</div>
</TableCell>
<!-- ... -->
</TableRow>
</TableBody>
</Table>
<div class="flex items-center justify-between mt-4">
<span class="text-sm text-zinc-500">Showing 1 to 3 of 24 results</span>
<Pagination totalPages={5} currentPage={1} baseUrl="/docs/components/table" /> Client-side Sorting
Add sortable and sortDirection to TableHeadCell to enable click-to-sort functionality. The table includes automatic string
and numeric sorting client-side out-of-the-box.
| Name | Age | Role |
|---|---|---|
| Alice Smith | 28 | Engineer |
| Charlie Brown | 42 | Manager |
| Bob Jones | 35 | Designer |
<Table>
<TableHead>
<TableRow>
<TableHeadCell sortable sortDirection="none">Name</TableHeadCell>
<TableHeadCell sortable sortDirection="none">Age</TableHeadCell>
<TableHeadCell sortable sortDirection="none">Role</TableHeadCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>Alice Smith</TableCell>
<TableCell>28</TableCell>
<TableCell>Engineer</TableCell>
</TableRow>
<TableRow>
<TableCell>Charlie Brown</TableCell>
<TableCell>42</TableCell>
<TableCell>Manager</TableCell>
</TableRow>
<TableRow>
<TableCell>Bob Jones</TableCell>
<TableCell>35</TableCell>
<TableCell>Designer</TableCell>
</TableRow>
</TableBody>
</Table> Client-side Filtering
Use an external or nested input field equipped with data-filter-table="true" and data-filter-col="index" to instantly filter row contents
based on column matches.
| ID | User | Email |
|---|---|---|
| 1 | Alice Smith | alice@smith.com |
| 2 | Bob Jones | bob@jones.com |
| 3 | Charlie Brown | charlie@brown.com |
<div class='mb-2 w-64'>
<TextInput
iconLeft='Search'
placeholder='Filter emails...'
data-filter-table='true'
data-filter-col='2'
/>
</div>
<Table>
<TableHead>
<TableRow>
<TableHeadCell>ID</TableHeadCell>
<TableHeadCell>User</TableHeadCell>
<TableHeadCell>Email</TableHeadCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>1</TableCell>
<TableCell>Alice Smith</TableCell>
<TableCell>alice@smith.com</TableCell>
</TableRow>
<TableRow>
<TableCell>2</TableCell>
<TableCell>Bob Jones</TableCell>
<TableCell>bob@jones.com</TableCell>
</TableRow>
<TableRow>
<TableCell>3</TableCell>
<TableCell>Charlie Brown</TableCell>
<TableCell>charlie@brown.com</TableCell>
</TableRow>
</TableBody>
</Table>
<Table>
<TableHead>
<TableRow>
<TableHeadCell>ID</TableHeadCell> <!-- Index 0 -->
<TableHeadCell>User</TableHeadCell> <!-- Index 1 -->
<TableHeadCell>Email</TableHeadCell> <!-- Index 2 -->
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>1</TableCell>
<TableCell>Alice Smith</TableCell>
<TableCell>alice@smith.com</TableCell>
</TableRow>
<!-- ... -->
</TableBody>
</Table> Resizing Columns
Add resizable to TableHeadCell to render a drag
handle on the right edge of the header, allowing horizontal column adjustment.
Note: This requires fixed table layouts (`table-fixed`).
| Company | Contact | Country |
|---|---|---|
| Acme Corp | John Doe | USA |
| Globex | Jane Smith | UK |
<!-- Table should use fixed layout to prevent columns from snapping back -->
<Table class="table-fixed">
<TableHead>
<TableRow>
<TableHeadCell resizable class="w-1/3">Company</TableHeadCell>
<TableHeadCell resizable class="w-1/3">Contact</TableHeadCell>
<TableHeadCell class="w-1/3">Country</TableHeadCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>Acme Corp</TableCell>
<TableCell>John Doe</TableCell>
<TableCell>USA</TableCell>
</TableRow>
</TableBody>
</Table> Drag and Drop Columns
Add draggable to TableHeadCell to enable dragging
columns left/right. The table script automatically manages column DOM shifts.
| ID
| Product
| Price
|
|---|---|---|
| 001 | Laptop | $999 |
| 002 | Phone | $599 |
<Table>
<TableHead>
<TableRow>
<TableHeadCell draggable>
<div class='flex items-center gap-2'>
<Icon name='GripVertical' class='h-4 w-4 text-zinc-400' /> ID
</div>
</TableHeadCell>
<TableHeadCell draggable>
<div class='flex items-center gap-2'>
<Icon name='GripVertical' class='h-4 w-4 text-zinc-400' /> Product
</div>
</TableHeadCell>
<TableHeadCell draggable>
<div class='flex items-center gap-2'>
<Icon name='GripVertical' class='h-4 w-4 text-zinc-400' /> Price
</div>
</TableHeadCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>001</TableCell>
<TableCell>Laptop</TableCell>
<TableCell>$999</TableCell>
</TableRow>
<TableRow>
<TableCell>002</TableCell>
<TableCell>Phone</TableCell>
<TableCell>$599</TableCell>
</TableRow>
</TableBody>
</Table> ID
</div>
</TableHeadCell>
<TableHeadCell draggable>
<div class="flex items-center gap-2">
<Icon name="GripVertical" class="h-4 w-4 text-zinc-400" /> Product
</div>
</TableHeadCell>
<TableHeadCell draggable>
<div class="flex items-center gap-2">
<Icon name="GripVertical" class="h-4 w-4 text-zinc-400" /> Price
</div>
</TableHeadCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>001</TableCell>
<TableCell>Laptop</TableCell>
<TableCell>$999</TableCell>
</TableRow>
</TableBody>
</Table> Row Grouping
Tables can group rows together. Use data-group-header="true", data-group-id, and aria-expanded on the header
row, and data-group="id" on the child rows. The component includes
built-in client-side toggle logic.
| Team Member | Role | Status |
|---|---|---|
|
Engineering (2)
| ||
| Alice Smith | Frontend Developer | Active |
| Bob Jones | Backend Developer | Active |
|
Design (1)
| ||
<Table>
<TableHead>
<TableRow>
<TableHeadCell>Team Member</TableHeadCell>
<TableHeadCell>Role</TableHeadCell>
<TableHeadCell>Status</TableHeadCell>
</TableRow>
</TableHead>
<TableBody>
<!-- Group Header -->
<TableRow
data-group-header='true'
data-group-id='engineering'
aria-expanded='true'
class='bg-zinc-100 dark:bg-zinc-800/80 hover:bg-zinc-200 dark:hover:bg-zinc-700'>
<TableCell colspan={3} class='font-medium'>
<div class='flex items-center gap-2'>
<Icon
name='ChevronRight'
class='h-4 w-4 transition-transform rotate-90'
data-group-icon
/>
Engineering (2)
</div>
</TableCell>
</TableRow>
<!-- Group Rows -->
<TableRow data-group='engineering'>
<TableCell>Alice Smith</TableCell>
<TableCell>Frontend Developer</TableCell>
<TableCell><Tag>Active</Tag></TableCell>
</TableRow>
<TableRow data-group='engineering'>
<TableCell>Bob Jones</TableCell>
<TableCell>Backend Developer</TableCell>
<TableCell><Tag>Active</Tag></TableCell>
</TableRow>
<!-- Group Header -->
<TableRow
data-group-header='true'
data-group-id='design'
aria-expanded='false'
class='bg-zinc-100 dark:bg-zinc-800/80 hover:bg-zinc-200 dark:hover:bg-zinc-700'>
<TableCell colspan={3} class='font-medium'>
<div class='flex items-center gap-2'>
<Icon
name='ChevronRight'
class='h-4 w-4 transition-transform'
data-group-icon
/>
Design (1)
</div>
</TableCell>
</TableRow>
<!-- Group Rows -->
<TableRow data-group='design' class='hidden'>
<TableCell>Charlie Brown</TableCell>
<TableCell>UI/UX Designer</TableCell>
<TableCell><Tag>On Leave</Tag></TableCell>
</TableRow>
</TableBody>
</Table>
Engineering
</div>
</TableCell>
</TableRow>
<TableRow data-group="group1">
<TableCell>Alice</TableCell>
<TableCell>Frontend</TableCell>
</TableRow>
<TableRow data-group="group1">
<TableCell>Bob</TableCell>
<TableCell>Backend</TableCell>
</TableRow>
<!-- Group 2 -->
<TableRow data-group-header="true" data-group-id="group2" aria-expanded="false">
<TableCell colspan={2}>
<div class="flex items-center gap-2">
<Icon name="ChevronRight" class="h-4 w-4" data-group-icon />
Design
</div>
</TableCell>
</TableRow>
<TableRow data-group="group2" class="hidden">
<TableCell>Charlie</TableCell>
<TableCell>UI/UX</TableCell>
</TableRow>
</TableBody>
</Table> Table
Tables can contain complex interactive elements like form inputs, allowing inline editing.
| | Product | Category | Price | Stock |
|---|---|---|---|---|
| | | | | |
| | | | | |
| | | | |
<Table>
<TableHead>
<TableRow>
<TableHeadCell class='w-12'><Checkbox /></TableHeadCell>
<TableHeadCell>Product</TableHeadCell>
<TableHeadCell>Category</TableHeadCell>
<TableHeadCell>Price</TableHeadCell>
<TableHeadCell>Stock</TableHeadCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell><Checkbox checked /></TableCell>
<TableCell padding='none'
><TextInput
value='Laptop Pro'
placeholder='Product name'
class='w-full h-full min-h-11 min-w-37.5 border-0 focus:ring-0 rounded-none bg-transparent'
/></TableCell
>
<TableCell padding='none'>
<Select
class='w-full h-full min-h-11 min-w-37.5'
triggerClass='border-0 focus:ring-0 rounded-none bg-transparent h-full'>
<SelectOption value='electronics' label='Electronics' />
<SelectOption value='clothing' label='Clothing' />
<SelectOption value='home' label='Home & Garden' />
</Select>
</TableCell>
<TableCell padding='none'
><TextInput
type='number'
value='1299'
class='w-full h-full min-h-11 min-w-25 border-0 focus:ring-0 rounded-none bg-transparent'
/></TableCell
>
<TableCell padding='none'
><TextInput
type='number'
value='45'
class='w-full h-full min-h-11 min-w-20 border-0 focus:ring-0 rounded-none bg-transparent'
/></TableCell
>
</TableRow>
<TableRow>
<TableCell><Checkbox /></TableCell>
<TableCell padding='none'
><TextInput
value='Wireless Mouse'
placeholder='Product name'
class='w-full h-full min-h-11 min-w-37.5 border-0 focus:ring-0 rounded-none bg-transparent'
/></TableCell
>
<TableCell padding='none'>
<Select
class='w-full h-full min-h-11 min-w-37.5'
triggerClass='border-0 focus:ring-0 rounded-none bg-transparent h-full'>
<SelectOption value='electronics' label='Electronics' />
<SelectOption value='clothing' label='Clothing' />
<SelectOption value='home' label='Home & Garden' />
</Select>
</TableCell>
<TableCell padding='none'
><TextInput
type='number'
value='49'
class='w-full h-full min-h-11 min-w-25 border-0 focus:ring-0 rounded-none bg-transparent'
/></TableCell
>
<TableCell padding='none'
><TextInput
type='number'
value='120'
class='w-full h-full min-h-11 min-w-20 border-0 focus:ring-0 rounded-none bg-transparent'
/></TableCell
>
</TableRow>
<TableRow>
<TableCell><Checkbox checked /></TableCell>
<TableCell padding='none'
><TextInput
value='Cotton T-Shirt'
placeholder='Product name'
class='w-full h-full min-h-11 min-w-37.5 border-0 focus:ring-0 rounded-none bg-transparent'
/></TableCell
>
<TableCell padding='none'>
<Select
class='w-full h-full min-h-11 min-w-37.5'
triggerClass='border-0 focus:ring-0 rounded-none bg-transparent h-full'>
<SelectOption value='electronics' label='Electronics' />
<SelectOption value='clothing' label='Clothing' />
<SelectOption value='home' label='Home & Garden' />
</Select>
</TableCell>
<TableCell padding='none'
><TextInput
type='number'
value='19'
class='w-full h-full min-h-11 min-w-25 border-0 focus:ring-0 rounded-none bg-transparent'
/></TableCell
>
<TableCell padding='none'
><TextInput
type='number'
value='300'
class='w-full h-full min-h-11 min-w-20 border-0 focus:ring-0 rounded-none bg-transparent'
/></TableCell
>
</TableRow>
</TableBody>
</Table></TableHeadCell>
<TableHeadCell>Product</TableHeadCell>
<TableHeadCell>Category</TableHeadCell>
<TableHeadCell>Price</TableHeadCell>
<TableHeadCell>Stock</TableHeadCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell><Checkbox checked /></TableCell>
<TableCell padding="none"><TextInput value="Laptop Pro" placeholder="Product name" class="w-full h-full min-h-11 min-w-37.5 border-0 focus:ring-0 rounded-none bg-transparent" /></TableCell>
<TableCell padding="none">
<Select class="w-full h-full min-h-11 min-w-37.5" triggerClass="border-0 focus:ring-0 rounded-none bg-transparent h-full">
<SelectOption value="electronics" label="Electronics" />
<SelectOption value="clothing" label="Clothing" />
<SelectOption value="home" label="Home & Garden" />
</Select>
</TableCell>
<TableCell padding="none"><TextInput type="number" value="1299" class="w-full h-full min-h-11 min-w-25 border-0 focus:ring-0 rounded-none bg-transparent" /></TableCell>
<TableCell padding="none"><TextInput type="number" value="45" class="w-full h-full min-h-11 min-w-20 border-0 focus:ring-0 rounded-none bg-transparent" /></TableCell>
</TableRow>
<!-- Additional rows... -->
</TableBody>
</Table> Table
Tables can be configured with sortable columns, draggable columns, and resizable columns.
| Name | Age | Location |
|---|---|---|
| Alice | 28 | New York |
| Bob | 34 | San Francisco |
| Charlie | 22 | London |
---
import Table from '@/components/data-display/Table.astro';
import TableHead from '@/components/data-display/TableHead.astro';
import TableRow from '@/components/data-display/TableRow.astro';
import TableHeadCell from '@/components/data-display/TableHeadCell.astro';
import TableBody from '@/components/data-display/TableBody.astro';
import TableCell from '@/components/data-display/TableCell.astro';
---
<Table>
<TableHead>
<TableRow>
<TableHeadCell sortable sortDirection="asc" resizable draggable>Name</TableHeadCell>
<TableHeadCell sortable resizable draggable>Age</TableHeadCell>
<TableHeadCell sortable resizable draggable>Location</TableHeadCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>Alice</TableCell>
<TableCell>28</TableCell>
<TableCell>New York</TableCell>
</TableRow>
<TableRow>
<TableCell>Bob</TableCell>
<TableCell>34</TableCell>
<TableCell>San Francisco</TableCell>
</TableRow>
</TableBody>
</Table> Table
Tables can easily integrate with the Pagination component for handling large datasets.
| ID | User | Role |
|---|---|---|
| 001 | John Doe | Admin |
| 002 | Jane Smith | User |
<Table>
<TableHead>
<TableRow>
<TableHeadCell>ID</TableHeadCell>
<TableHeadCell>User</TableHeadCell>
<TableHeadCell>Role</TableHeadCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>001</TableCell>
<TableCell>John Doe</TableCell>
<TableCell>Admin</TableCell>
</TableRow>
<TableRow>
<TableCell>002</TableCell>
<TableCell>Jane Smith</TableCell>
<TableCell>User</TableCell>
</TableRow>
</TableBody>
</Table>
<div class="mt-4 flex justify-center">
<Pagination totalPages={5} currentPage={1} baseUrl="#" />
</div>
</div> API Reference
Table
| Property | Description | Type | Default |
|---|---|---|---|
| size | Table size preset | 'sm' | 'md' | 'lg' | 'md' |
| striped | Applies striped row styling | boolean | false |
| bordered | Applies a border to the table container | boolean | true |
| maxHeight | Applies a max-height (500px) and enables scrolling | boolean | false |
| containerClass | Custom classes for the table container | string | '' |
TableCell
| Property | Description | Type | Default |
|---|---|---|---|
| align | Text alignment for the cell | 'left' | 'center' | 'right' | 'left' |
| padding | Padding reset for custom contents | 'default' | 'none' | 'default' |
TableHeadCell
| Property | Description | Type | Default |
|---|---|---|---|
| sticky | Makes the header cell sticky | boolean | false |
| sortable | Enables column sorting | boolean | false |
| resizable | Enables column resizing | boolean | false |
| draggable | Enables column drag and drop reordering | boolean | false |