Table

A powerful data display component that provides sorting, pagination, row selection, and custom cell content. It's built with composable parts and the defineTable composable to create complex interactive data tables. It is also the only component which should be imported as a namespace and not as separate atomic components.

If you have tables with a lot of horizontal content, wrap them in a .vui-table-overflow class seamless vertical scrollbar setup.

id
name
age
1John Doe30
2Jane Smith25
3Bob Johnson35

Props

Table.Root Props

NameDefaultType
fixedfalseboolean
Sets the table-layout property to fixed
nowrapfalseboolean
Prevents cell content from wrapping to new lines
separateRowstrueboolean
Adds a visual separator between rows
separateCellsfalseboolean
Adds a visual separator between cells
outerBordertrueboolean
Adds a border around the table

Table.Head Props

NameDefaultType
headerHeader
Header data including label and sort state
sortfalseboolean
Enables sorting for the column

Table.SelectRow Props

NameDefaultType
rowBaseRow
Row data for selection

Slots

Table.Root Slots

SlotDescription
headerContent for the table header row
bodyContent for the table body rows
paginationContent for the pagination section

Table.Head Slots

SlotDescription
defaultCustom header content

Table.Cell Slots

SlotDescription
defaultMain cell content
contextAdditional content that appears on the right side of the cell

defineTable API

The defineTable composable is the core of the table system, providing reactive data management with built-in sorting, pagination, and selection.

import { defineTable, Pagination, Table } from '@dolanske/vui'

const data = [
  { id: 1, name: 'John Doe', age: 30 },
  { id: 2, name: 'Jane Smith', age: 25 },
]

const { headers, rows, pagination, setPage } = defineTable(data, {
  pagination: {
    enabled: true,
    perPage: 1,
  },
  select: true,
})

It is a separate API, because it allows you to build your own table-like UI without having to use the provided Table namespace. It doesn't even need to look like one!

Parameters

NameDefaultType
dataMaybeRefOrGetter<T[]>
The dataset to display in the table
optionsTableOptionsInput
Configuration options

Options

NameDefaultType
pagination.enabledfalseboolean
Enable pagination
pagination.perPage10number
Number of items per page
pagination.maxPages3number
Maximum number of page buttons
selectfalseboolean
Enable row selection

Returns

The defineTable composable returns an object with the following reactive properties and methods:

Methods
NameTypeDescription
setSort(key: string, type: 'asc' | 'desc' | 'toggle') => voidSet sorting for a specific column key
clearSort() => voidClear current sorting
setPage(page: number) => voidNavigate to a specific page (1-indexed)
selectRow(row: T) => voidToggle selection state of a specific row
selectAllRows() => voidToggle selection of all rows
Properties
NameTypeDescription
searchRef<string>Reactive search query string
rowsComputedRef<T[]>Filtered and paginated dataset rows
allRowsComputedRef<T[]>All filtered rows (without pagination)
selectedRowsComputedRef<Set<T>>Set of currently selected rows
headersComputedRef<Header[]>Table headers with sorting functionality
paginationComputedRef<PaginationResult>Pagination state and metadata
canPrevPageComputedRef<boolean>Whether previous page navigation is available
canNextPageComputedRef<boolean>Whether next page navigation is available
optionsRef<DeepRequired<TableOptionsInput>>Reactive table configuration options
isSelectedAllComputedRef<boolean>Whether all rows are currently selected

Examples

Custom Cell content

id
name
status
1
JohnActive
2
JaneInactive