On this page

Table

Live examples of Table, with the exact Vue file that renders each one.

Every example is a complete Vue file. Copy it into an app that has the registry installed, or open it in StackBlitz.

Records with a status

IDs in the code font, numbers right-aligned, a status label per row. Rows show a light fill on hover.

Orders from the online store, newest first.
OrderCustomerTotalERP sync
#10482Green Leaf Cafe1,250,000 ₫
Synced
#10481Sunrise Bakery860,000 ₫
Syncing
#10479Blue River Hotel4,720,000 ₫
Failed
#10475Lotus Spa395,000 ₫
Paused
TableOrders.vue
<script setup lang="ts">
import { Badge } from '@/components/ui/badge'
import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'

const orders = [
  { id: '#10482', customer: 'Green Leaf Cafe', total: '1,250,000 ₫', status: 'Synced', variant: 'success' },
  { id: '#10481', customer: 'Sunrise Bakery', total: '860,000 ₫', status: 'Syncing', variant: 'info' },
  { id: '#10479', customer: 'Blue River Hotel', total: '4,720,000 ₫', status: 'Failed', variant: 'danger' },
  { id: '#10475', customer: 'Lotus Spa', total: '395,000 ₫', status: 'Paused', variant: 'neutral' },
] as const
</script>

<template>
  <Table>
    <TableCaption>Orders from the online store, newest first.</TableCaption>
    <TableHeader>
      <TableRow>
        <TableHead>Order</TableHead>
        <TableHead>Customer</TableHead>
        <TableHead class="text-end">Total</TableHead>
        <TableHead>ERP sync</TableHead>
      </TableRow>
    </TableHeader>
    <TableBody>
      <TableRow v-for="order in orders" :key="order.id">
        <TableCell class="[font:var(--bh-font-code-default)]">{{ order.id }}</TableCell>
        <TableCell>{{ order.customer }}</TableCell>
        <TableCell class="text-end tabular-nums">{{ order.total }}</TableCell>
        <TableCell><Badge :variant="order.variant">{{ order.status }}</Badge></TableCell>
      </TableRow>
    </TableBody>
  </Table>
</template>

Selected rows

Set data-state="selected" on a chosen row: it gets the selected fill and a yellow bar at its start, so selection does not rely on the fill alone.

SelectSKUProductIn stock
TEA-001Jasmine green tea, 100 g120
TEA-014Oolong tea, 250 g48
CUP-203Ceramic cup, white0
TableSelectable.vue
<script setup lang="ts">
import { ref } from 'vue'
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'

const products = [
  { sku: 'TEA-001', name: 'Jasmine green tea, 100 g', stock: 120 },
  { sku: 'TEA-014', name: 'Oolong tea, 250 g', stock: 48 },
  { sku: 'CUP-203', name: 'Ceramic cup, white', stock: 0 },
]
const selected = ref<string[]>(['TEA-014'])
</script>

<template>
  <Table>
    <TableHeader>
      <TableRow>
        <TableHead class="w-0"><span class="sr-only">Select</span></TableHead>
        <TableHead>SKU</TableHead>
        <TableHead>Product</TableHead>
        <TableHead class="text-end">In stock</TableHead>
      </TableRow>
    </TableHeader>
    <TableBody>
      <TableRow
        v-for="product in products"
        :key="product.sku"
        :data-state="selected.includes(product.sku) ? 'selected' : undefined"
      >
        <TableCell>
          <input
            v-model="selected"
            type="checkbox"
            :value="product.sku"
            :aria-label="`Select ${product.name}`"
            class="size-(--bh-size-icon-default) accent-(--bh-color-background-primary)"
          >
        </TableCell>
        <TableCell class="[font:var(--bh-font-code-default)]">{{ product.sku }}</TableCell>
        <TableCell>{{ product.name }}</TableCell>
        <TableCell class="text-end tabular-nums">{{ product.stock }}</TableCell>
      </TableRow>
    </TableBody>
  </Table>
</template>

Long values

table-fixed on the table and break-all on the cell: a URL or key wraps inside its column instead of pushing the others off screen. Never cut a value people copy.

SettingValue
Webhook URLhttps://erp.example.com/api/v2/webhooks/orders/created?tenant=store-0193
Signing keywhsec_9f2c4e81b7a64d0f93c1e5a7b2d8f6c40e1a9b3d
Retry limit5
TableLongValues.vue
<script setup lang="ts">
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'

// Keys and URLs have no spaces to wrap at. table-fixed keeps the column widths; break-all wraps the value
// inside its column instead of pushing the other columns off screen. Never cut a value people copy.
const settings = [
  { name: 'Webhook URL', value: 'https://erp.example.com/api/v2/webhooks/orders/created?tenant=store-0193' },
  { name: 'Signing key', value: 'whsec_9f2c4e81b7a64d0f93c1e5a7b2d8f6c40e1a9b3d' },
  { name: 'Retry limit', value: '5' },
]
</script>

<template>
  <Table class="table-fixed">
    <TableHeader>
      <TableRow>
        <TableHead class="w-[35%]">Setting</TableHead>
        <TableHead>Value</TableHead>
      </TableRow>
    </TableHeader>
    <TableBody>
      <TableRow v-for="setting in settings" :key="setting.name">
        <TableCell class="align-top">{{ setting.name }}</TableCell>
        <TableCell class="align-top break-all [font:var(--bh-font-code-default)]">{{ setting.value }}</TableCell>
      </TableRow>
    </TableBody>
  </Table>
</template>

No rows

TableEmpty spans every column. Say why there are no rows.

OrderCustomerERP sync
No orders match "Lotus".
TableNoRows.vue
<script setup lang="ts">
import { Table, TableBody, TableEmpty, TableHead, TableHeader, TableRow } from '@/components/ui/table'
</script>

<template>
  <Table>
    <TableHeader>
      <TableRow>
        <TableHead>Order</TableHead>
        <TableHead>Customer</TableHead>
        <TableHead>ERP sync</TableHead>
      </TableRow>
    </TableHeader>
    <TableBody>
      <TableEmpty :colspan="3">No orders match "Lotus".</TableEmpty>
    </TableBody>
  </Table>
</template>