VelocityUI logoVelocityUI

Table

Sortable data table with optional striped rows and bordered cells. Column definitions support a custom cell render function.

Import

tsx
import { Table } from '@velocityuikit/velocityui'

Preview

Sortable

NameRoleStatusJoined
Alice BrownEngineerActive2022-03
Bob ChenDesignerInactive2021-07
Carol DavisManagerActive2020-11
Dan EvansEngineerActive2023-01

Striped and bordered

NameRoleStatus
Alice BrownEngineerActive
Bob ChenDesignerInactive
Carol DavisManagerActive
Dan EvansEngineerActive

Props

PropTypeDefaultDescription
columns{ key: string; header: string; sortable?: boolean; render?: (value, row, index) => ReactNode }[]Column definitions.
dataT[]Array of row data objects.
sortKeystringThe column key currently sorted.
sortDir'asc' | 'desc'The current sort direction.
onSort(key: string, dir: SortDirection) => voidCallback fired when a sortable header is clicked.
stripedbooleanfalseAlternates row background colors.
borderedbooleanfalseAdds borders to individual cells.
size'sm' | 'md' | 'lg''md'Controls cell padding and font size.

Examples

Basic sortable table

tsx
import { Table } from '@velocityuikit/velocityui'
import { useState } from 'react'

const data = [
  { name: 'Alice', role: 'Engineer', status: 'Active' },
  { name: 'Bob', role: 'Designer', status: 'Inactive' },
  { name: 'Carol', role: 'Manager', status: 'Active' },
]

export default function Example() {
  const [sortKey, setSortKey] = useState('')
  const [sortDir, setSortDir] = useState('asc')

  const sorted = [...data].sort((a, b) => {
    if (!sortKey) return 0
    const cmp = a[sortKey] < b[sortKey] ? -1 : a[sortKey] > b[sortKey] ? 1 : 0
    return sortDir === 'asc' ? cmp : -cmp
  })

  return (
    <Table
      columns={[
        { key: 'name', header: 'Name', sortable: true },
        { key: 'role', header: 'Role', sortable: true },
        { key: 'status', header: 'Status' },
      ]}
      data={sorted}
      sortKey={sortKey}
      sortDir={sortDir}
      onSort={(key, dir) => { setSortKey(key); setSortDir(dir) }}
    />
  )
}

Striped and bordered

tsx
import { Table } from '@velocityuikit/velocityui'

const data = [
  { id: 1, product: 'Widget A', price: '$12.00' },
  { id: 2, product: 'Widget B', price: '$8.50' },
  { id: 3, product: 'Widget C', price: '$24.99' },
]

export default function Example() {
  return (
    <Table
      columns={[
        { key: 'id', header: '#' },
        { key: 'product', header: 'Product' },
        { key: 'price', header: 'Price' },
      ]}
      data={data}
      striped
      bordered
    />
  )
}

Theming

Apply a named theme class to <body> or any parent element. All VelocityUI components inside that element will automatically adopt its colors, shadows, and effects. Combine with a density modifier for complete control:

css
/* Pick any named theme */
<body class="vui-theme-ocean">

/* Add a density modifier (optional) */
<body class="vui-theme-midnight vui-density-compact">
<body class="vui-theme-construction vui-density-spacious">

/* Available themes */
/* default  midnight  ocean  tangerine */
/* construction  glass  soft  high-contrast  monochrome-red */

/* Available densities */
/* vui-density-compact  vui-density-comfortable  vui-density-spacious */