Keyboard shortcut: Ctrl + K
Get started

Data table

VDataTable displays rows with search, sorting, selection and pagination. Process data locally or use server mode to request each result set.

Usage

vue
Projects
ProjectOwnerCommits
Vectis UIAda Lovelace320
AtlasGrace Hopper87
MeridianAlan Turing44
<script setup lang="ts">
import { VDataTable } from 'vectis-ui'

const columns = [
  { key: 'name', label: 'Project' },
  { key: 'owner', label: 'Owner' },
  { key: 'commits', label: 'Commits' },
]

const rows = [
  { name: 'Vectis UI', owner: 'Ada Lovelace', commits: 320 },
  { name: 'Atlas', owner: 'Grace Hopper', commits: 87 },
  { name: 'Meridian', owner: 'Alan Turing', commits: 44 },
]
</script>

<template>
  <VDataTable :columns="columns" :rows="rows" row-key="name" title="Projects" />
</template>

Examples

Sorting

Mark columns sortable. Their headings cycle through ascending, descending and original order. Observe or set the sort with v-model:sort.

vue
Projects
Owner
BrumeLouisArchived1204
VectisXavierActive320
AtlasNadiaActive87
GranitEmmaActive45

Sorted by commits, descending

<script setup lang="ts">
import { ref } from 'vue'
import { VDataTable, type DataTableSort } from 'vectis-ui'

const columns = [
  { key: 'name', label: 'Project', sortable: true },
  { key: 'owner', label: 'Owner' },
  { key: 'status', label: 'Status', sortable: true },
  { key: 'commits', label: 'Commits', sortable: true, align: 'end' as const },
]

const rows = [
  { name: 'Vectis', owner: 'Xavier', status: 'Active', commits: 320 },
  { name: 'Atlas', owner: 'Nadia', status: 'Active', commits: 87 },
  { name: 'Brume', owner: 'Louis', status: 'Archived', commits: 1204 },
  { name: 'Granit', owner: 'Emma', status: 'Active', commits: 45 },
]

const sort = ref<DataTableSort | null>({ key: 'commits', direction: 'desc' })

const DIRECTIONS = { asc: 'ascending', desc: 'descending' }
</script>

<template>
  <div class="demo">
    <VDataTable
      v-model:sort="sort"
      :columns="columns"
      :rows="rows"
      row-key="name"
      title="Projects"
    />
    <p class="state">
      Sorted by {{ sort ? `${sort.key}, ${DIRECTIONS[sort.direction]}` : 'nothing' }}
    </p>
  </div>
</template>

<style scoped>
.demo {
  display: grid;
  gap: var(--vectis-space-3);
}
.state {
  margin: 0;
  color: var(--vectis-color-text-muted);
  font-size: var(--vectis-text-body-sm-size);
}
</style>

searchable adds a field searching declared columns without case or accent sensitivity. Control the query with v-model:search.

vue
Projects
OwnerStatusCommits
VectisXavierActive320
AtlasNadiaActive87
BrumeLouisArchived1204
GranitEmmaActive45
ÉclairXavierActive296
FalaiseNadiaArchived133
GivreLouisActive58
HouleEmmaActive411
<script setup lang="ts">
import { VDataTable } from 'vectis-ui'

const columns = [
  { key: 'name', label: 'Project', sortable: true },
  { key: 'owner', label: 'Owner' },
  { key: 'status', label: 'Status' },
  { key: 'commits', label: 'Commits', align: 'end' as const },
]

const rows = [
  { name: 'Vectis', owner: 'Xavier', status: 'Active', commits: 320 },
  { name: 'Atlas', owner: 'Nadia', status: 'Active', commits: 87 },
  { name: 'Brume', owner: 'Louis', status: 'Archived', commits: 1204 },
  { name: 'Granit', owner: 'Emma', status: 'Active', commits: 45 },
  { name: 'Éclair', owner: 'Xavier', status: 'Active', commits: 296 },
  { name: 'Falaise', owner: 'Nadia', status: 'Archived', commits: 133 },
  { name: 'Givre', owner: 'Louis', status: 'Active', commits: 58 },
  { name: 'Houle', owner: 'Emma', status: 'Active', commits: 411 },
]
</script>

<template>
  <VDataTable
    :columns="columns"
    :rows="rows"
    row-key="name"
    title="Projects"
    searchable
    search-placeholder="Search projects"
    search-label="Search the projects"
  />
</template>

Pagination

Set v-model:per-page above 0 to enable pagination. showRange displays the visible row range.

vue
Projects
OwnerStatus
VectisXavierArchived111
AtlasNadiaActive148
BrumeLouisActive185
GranitEmmaArchived222
ÉclairXavierActive259
FalaiseNadiaActive296
<script setup lang="ts">
import { VDataTable } from 'vectis-ui'

const columns = [
  { key: 'name', label: 'Project', sortable: true },
  { key: 'owner', label: 'Owner' },
  { key: 'status', label: 'Status' },
  { key: 'commits', label: 'Commits', sortable: true, align: 'end' as const },
]

const NAMES = [
  'Vectis',
  'Atlas',
  'Brume',
  'Granit',
  'Éclair',
  'Falaise',
  'Givre',
  'Houle',
  'Islet',
  'Jade',
  'Karst',
  'Lande',
  'Mistral',
  'Nacre',
  'Ombre',
  'Pollen',
  'Quartz',
  'Rivage',
  'Sillage',
  'Tuile',
  'Vigie',
  'Zenith',
]
const OWNERS = ['Xavier', 'Nadia', 'Louis', 'Emma']

const rows = NAMES.map((name, index) => ({
  name,
  owner: OWNERS[index % OWNERS.length],
  status: index % 3 === 0 ? 'Archived' : 'Active',
  commits: ((index + 3) * 37) % 500,
}))
</script>

<template>
  <VDataTable
    :columns="columns"
    :rows="rows"
    row-key="name"
    title="Projects"
    searchable
    :per-page="6"
    show-range
  />
</template>

Rows per page

perPageOptions offers page sizes in the footer.

vue
Projects
OwnerStatus
VectisXavierArchived111
AtlasNadiaActive148
BrumeLouisActive185
GranitEmmaArchived222
ÉclairXavierActive259
<script setup lang="ts">
import { ref } from 'vue'
import { VDataTable } from 'vectis-ui'

const columns = [
  { key: 'name', label: 'Project', sortable: true },
  { key: 'owner', label: 'Owner' },
  { key: 'status', label: 'Status' },
  { key: 'commits', label: 'Commits', sortable: true, align: 'end' as const },
]

const NAMES = [
  'Vectis',
  'Atlas',
  'Brume',
  'Granit',
  'Éclair',
  'Falaise',
  'Givre',
  'Houle',
  'Islet',
  'Jade',
  'Karst',
  'Lande',
  'Mistral',
  'Nacre',
  'Ombre',
  'Pollen',
  'Quartz',
  'Rivage',
  'Sillage',
  'Tuile',
  'Vigie',
  'Zenith',
]
const OWNERS = ['Xavier', 'Nadia', 'Louis', 'Emma']

const rows = NAMES.map((name, index) => ({
  name,
  owner: OWNERS[index % OWNERS.length],
  status: index % 3 === 0 ? 'Archived' : 'Active',
  commits: ((index + 3) * 37) % 500,
}))

const perPage = ref(5)
</script>

<template>
  <VDataTable
    v-model:per-page="perPage"
    :columns="columns"
    :rows="rows"
    row-key="name"
    title="Projects"
    :per-page-options="[5, 10, 25]"
    show-range
  />
</template>

Selection

selectable adds row checkboxes and a page-wide checkbox. Provide a stable rowKey; v-model:selected contains those identifiers.

vue
Projects
OwnerStatus
VectisXavierActive320
AtlasNadiaActive87
BrumeLouisArchived1204
GranitEmmaActive45
ÉclairXavierActive296

Selected: Atlas

<script setup lang="ts">
import { ref } from 'vue'
import { VDataTable, type DataTableRowId } from 'vectis-ui'

const columns = [
  { key: 'name', label: 'Project', sortable: true },
  { key: 'owner', label: 'Owner' },
  { key: 'status', label: 'Status' },
  { key: 'commits', label: 'Commits', sortable: true, align: 'end' as const },
]

const rows = [
  { name: 'Vectis', owner: 'Xavier', status: 'Active', commits: 320 },
  { name: 'Atlas', owner: 'Nadia', status: 'Active', commits: 87 },
  { name: 'Brume', owner: 'Louis', status: 'Archived', commits: 1204 },
  { name: 'Granit', owner: 'Emma', status: 'Active', commits: 45 },
  { name: 'Éclair', owner: 'Xavier', status: 'Active', commits: 296 },
]

type Project = (typeof rows)[number]

const selected = ref<DataTableRowId[]>(['Atlas'])

const selectRowLabel = (row: Project) => `Select ${row.name}`
</script>

<template>
  <div class="demo">
    <VDataTable
      v-model:selected="selected"
      :columns="columns"
      :rows="rows"
      row-key="name"
      title="Projects"
      selectable
      :select-row-label="selectRowLabel"
      select-all-label="Select every project on this page"
    />
    <p class="state">Selected: {{ selected.length ? selected.join(', ') : 'nothing' }}</p>
  </div>
</template>

<style scoped>
.demo {
  display: grid;
  gap: var(--vectis-space-3);
}
.state {
  margin: 0;
  color: var(--vectis-color-text-muted);
  font-size: var(--vectis-text-body-sm-size);
}
</style>

Header and toolbar

subtitle describes the table under its title. The toolbar slot adds a row for actions and filters between the header and the table. The header slot replaces the title and subtitle; name the table with aria-label then.

vue
Projects

Every project in the organisation

OwnerStatus
VectisXavierActive320
AtlasNadiaActive87
BrumeLouisArchived1204
GranitEmmaActive45
ÉclairXavierArchived296
<script setup lang="ts">
import { computed, ref } from 'vue'
import { VButton, VDataTable, VMenu, VMenuItem } from 'vectis-ui'
import { expand_more as expandMore } from 'vectis-ui/icons'

const columns = [
  { key: 'name', label: 'Project', sortable: true },
  { key: 'owner', label: 'Owner' },
  { key: 'status', label: 'Status' },
  { key: 'commits', label: 'Commits', sortable: true, align: 'end' as const },
]

const rows = [
  { name: 'Vectis', owner: 'Xavier', status: 'Active', commits: 320 },
  { name: 'Atlas', owner: 'Nadia', status: 'Active', commits: 87 },
  { name: 'Brume', owner: 'Louis', status: 'Archived', commits: 1204 },
  { name: 'Granit', owner: 'Emma', status: 'Active', commits: 45 },
  { name: 'Éclair', owner: 'Xavier', status: 'Archived', commits: 296 },
]

/* Apply the custom filter before the table's own search. */
const status = ref('All')
const filtered = computed(() =>
  status.value === 'All' ? rows : rows.filter((row) => row.status === status.value),
)
</script>

<template>
  <VDataTable
    :columns="columns"
    :rows="filtered"
    row-key="name"
    searchable
    title="Projects"
    subtitle="Every project in the organisation"
  >
    <template #toolbar>
      <VMenu match-trigger>
        <template #trigger="{ triggerProps }">
          <VButton
            v-bind="triggerProps"
            variant="outline"
            tone="neutral"
            size="sm"
            :icon-end="expandMore"
          >
            Status: {{ status }}
          </VButton>
        </template>
        <VMenuItem
          v-for="option in ['All', 'Active', 'Archived']"
          :key="option"
          :label="option"
          @select="status = option"
        />
      </VMenu>
      <VButton size="sm">New project</VButton>
    </template>
  </VDataTable>
</template>

Custom cells

A slot matching a column key replaces its cells. It receives the row, raw value and column; sorting and search still use the raw value.

vue
Projects
OwnerStatus
Vectis Xavier DarmetActive320
Atlas Nadia RousseauActive87
Brume Louis FabreArchived1,204
Granit Emma LefortActive45
<script setup lang="ts">
import { VAvatar, VChip, VDataTable } from 'vectis-ui'

const columns = [
  { key: 'name', label: 'Project', sortable: true },
  { key: 'owner', label: 'Owner' },
  { key: 'status', label: 'Status' },
  { key: 'commits', label: 'Commits', sortable: true, align: 'end' as const },
]

const rows = [
  { name: 'Vectis', owner: 'Xavier Darmet', status: 'Active', commits: 320 },
  { name: 'Atlas', owner: 'Nadia Rousseau', status: 'Active', commits: 87 },
  { name: 'Brume', owner: 'Louis Fabre', status: 'Archived', commits: 1204 },
  { name: 'Granit', owner: 'Emma Lefort', status: 'Active', commits: 45 },
]

const numbers = new Intl.NumberFormat('en-GB')
</script>

<template>
  <VDataTable :columns="columns" :rows="rows" row-key="name" title="Projects">
    <template #cell-owner="{ row }">
      <span class="owner">
        <VAvatar :name="row.owner" size="xs" />
        {{ row.owner }}
      </span>
    </template>

    <template #cell-status="{ row }">
      <VChip :tone="row.status === 'Active' ? 'success' : 'neutral'" size="xs">
        {{ row.status }}
      </VChip>
    </template>

    <template #cell-commits="{ row }">
      <span class="figure">{{ numbers.format(row.commits) }}</span>
    </template>
  </VDataTable>
</template>

<style scoped>
.owner {
  display: inline-flex;
  align-items: center;
  gap: var(--vectis-space-2);
}
.figure {
  font-variant-numeric: tabular-nums;
}
</style>

Custom headings

Use head- followed by a column key to customize its heading. Sortable headings contain a button: keep slot content non-interactive.

vue
Projects
OwnerLast update
VectisXavier2 days ago320
AtlasNadia3 weeks ago87
BrumeLouisYesterday1204
GranitEmmaAn hour ago45
<script setup lang="ts">
import { VDataTable, VIcon } from 'vectis-ui'
import { code, schedule } from 'vectis-ui/icons'

const columns = [
  { key: 'name', label: 'Project', sortable: true },
  { key: 'owner', label: 'Owner' },
  { key: 'updated', label: 'Last update' },
  { key: 'commits', label: 'Commits', sortable: true, align: 'end' as const },
]

const rows = [
  { name: 'Vectis', owner: 'Xavier', updated: '2 days ago', commits: 320 },
  { name: 'Atlas', owner: 'Nadia', updated: '3 weeks ago', commits: 87 },
  { name: 'Brume', owner: 'Louis', updated: 'Yesterday', commits: 1204 },
  { name: 'Granit', owner: 'Emma', updated: 'An hour ago', commits: 45 },
]
</script>

<template>
  <VDataTable :columns="columns" :rows="rows" row-key="name" title="Projects">
    <template #head-updated="{ column }">
      <span class="heading"><VIcon :name="schedule" :size="16" />{{ column.label }}</span>
    </template>

    <!-- Sortable heading content sits inside a button; keep it non-interactive. -->
    <template #head-commits="{ column }">
      <span class="heading"><VIcon :name="code" :size="16" />{{ column.label }}</span>
    </template>
  </VDataTable>
</template>

<style scoped>
.heading {
  display: inline-flex;
  align-items: center;
  gap: var(--vectis-space-1);
}
</style>

Variants

flat leaves the table unframed. outline adds a border, elevated a raised surface with a shadow and filled a muted surface. The frame surrounds the rows and the footer; the header stays outside.

vue
flat
Owner
VectisXavier320
AtlasNadia87
BrumeLouis1204
outline
Owner
VectisXavier320
AtlasNadia87
BrumeLouis1204
elevated
Owner
VectisXavier320
AtlasNadia87
BrumeLouis1204
filled
Owner
VectisXavier320
AtlasNadia87
BrumeLouis1204
<script setup lang="ts">
import { VDataTable, type DataTableVariant } from 'vectis-ui'

const variants: DataTableVariant[] = ['flat', 'outline', 'elevated', 'filled']

const columns = [
  { key: 'name', label: 'Project', sortable: true },
  { key: 'owner', label: 'Owner' },
  { key: 'commits', label: 'Commits', sortable: true, align: 'end' as const },
]

const rows = [
  { name: 'Vectis', owner: 'Xavier', commits: 320 },
  { name: 'Atlas', owner: 'Nadia', commits: 87 },
  { name: 'Brume', owner: 'Louis', commits: 1204 },
]
</script>

<template>
  <div class="stack">
    <VDataTable
      v-for="variant in variants"
      :key="variant"
      :variant="variant"
      :columns="columns"
      :rows="rows"
      row-key="name"
      :title="variant"
      searchable
    />
  </div>
</template>

<style scoped>
.stack {
  display: grid;
  gap: var(--vectis-space-6);
}
</style>

Striped rows

striped tints alternate rows.

vue
Projects
OwnerStatus
VectisXavierActive320
AtlasNadiaActive87
BrumeLouisArchived1204
GranitEmmaActive45
ÉclairXavierActive296
FalaiseNadiaArchived133
<script setup lang="ts">
import { VDataTable } from 'vectis-ui'

const columns = [
  { key: 'name', label: 'Project', sortable: true },
  { key: 'owner', label: 'Owner' },
  { key: 'status', label: 'Status' },
  { key: 'commits', label: 'Commits', sortable: true, align: 'end' as const },
]

const rows = [
  { name: 'Vectis', owner: 'Xavier', status: 'Active', commits: 320 },
  { name: 'Atlas', owner: 'Nadia', status: 'Active', commits: 87 },
  { name: 'Brume', owner: 'Louis', status: 'Archived', commits: 1204 },
  { name: 'Granit', owner: 'Emma', status: 'Active', commits: 45 },
  { name: 'Éclair', owner: 'Xavier', status: 'Active', commits: 296 },
  { name: 'Falaise', owner: 'Nadia', status: 'Archived', commits: 133 },
]
</script>

<template>
  <VDataTable striped :columns="columns" :rows="rows" row-key="name" title="Projects" />
</template>

stickyHeader keeps headings visible in a bounded scroll area. Set height or constrain the parent height.

vue
Projects
OwnerStatus
VectisXavierArchived111
AtlasNadiaActive148
BrumeLouisActive185
GranitEmmaArchived222
ÉclairXavierActive259
FalaiseNadiaActive296
GivreLouisArchived333
HouleEmmaActive370
IsletXavierActive407
JadeNadiaArchived444
KarstLouisActive481
LandeEmmaActive18
MistralXavierArchived55
NacreNadiaActive92
OmbreLouisActive129
PollenEmmaArchived166
QuartzXavierActive203
RivageNadiaActive240
SillageLouisArchived277
TuileEmmaActive314
VigieXavierActive351
ZenithNadiaArchived388
<script setup lang="ts">
import { VDataTable } from 'vectis-ui'

const columns = [
  { key: 'name', label: 'Project', sortable: true },
  { key: 'owner', label: 'Owner' },
  { key: 'status', label: 'Status' },
  { key: 'commits', label: 'Commits', sortable: true, align: 'end' as const },
]

const NAMES = [
  'Vectis',
  'Atlas',
  'Brume',
  'Granit',
  'Éclair',
  'Falaise',
  'Givre',
  'Houle',
  'Islet',
  'Jade',
  'Karst',
  'Lande',
  'Mistral',
  'Nacre',
  'Ombre',
  'Pollen',
  'Quartz',
  'Rivage',
  'Sillage',
  'Tuile',
  'Vigie',
  'Zenith',
]
const OWNERS = ['Xavier', 'Nadia', 'Louis', 'Emma']

const rows = NAMES.map((name, index) => ({
  name,
  owner: OWNERS[index % OWNERS.length],
  status: index % 3 === 0 ? 'Archived' : 'Active',
  commits: ((index + 3) * 37) % 500,
}))
</script>

<template>
  <VDataTable
    sticky-header
    variant="outline"
    :height="320"
    :columns="columns"
    :rows="rows"
    row-key="name"
    title="Projects"
  />
</template>

Full height

height bounds the whole component, including header, toolbar and footer. Numbers use pixels; strings use CSS lengths.

vue
Projects
OwnerStatus
VectisXavierArchived111
AtlasNadiaActive148
BrumeLouisActive185
GranitEmmaArchived222
ÉclairXavierActive259
<script setup lang="ts">
import { VDataTable } from 'vectis-ui'

const columns = [
  { key: 'name', label: 'Project', sortable: true },
  { key: 'owner', label: 'Owner' },
  { key: 'status', label: 'Status' },
  { key: 'commits', label: 'Commits', sortable: true, align: 'end' as const },
]

const NAMES = [
  'Vectis',
  'Atlas',
  'Brume',
  'Granit',
  'Éclair',
  'Falaise',
  'Givre',
  'Houle',
  'Islet',
  'Jade',
  'Karst',
  'Lande',
]
const OWNERS = ['Xavier', 'Nadia', 'Louis', 'Emma']

const rows = NAMES.map((name, index) => ({
  name,
  owner: OWNERS[index % OWNERS.length],
  status: index % 3 === 0 ? 'Archived' : 'Active',
  commits: ((index + 3) * 37) % 500,
}))
</script>

<template>
  <div class="panel">
    <VDataTable
      variant="outline"
      sticky-header
      :columns="columns"
      :rows="rows"
      row-key="name"
      title="Projects"
      searchable
      :per-page="5"
      :per-page-options="[5, 10]"
      show-range
    />
  </div>
</template>

<style scoped>
.panel {
  block-size: 26rem;
}
</style>

Server side

serverSide displays supplied rows without local search, sort or pagination. Listen to update:params, fetch the rows and provide total. searchDebounce delays search requests.

vue
Projects
OwnerStatus
Loading data…
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { VDataTable, type DataTableParams } from 'vectis-ui'

const columns = [
  { key: 'name', label: 'Project', sortable: true },
  { key: 'owner', label: 'Owner' },
  { key: 'status', label: 'Status' },
  { key: 'commits', label: 'Commits', sortable: true, align: 'end' as const },
]

const NAMES = [
  'Vectis',
  'Atlas',
  'Brume',
  'Granit',
  'Éclair',
  'Falaise',
  'Givre',
  'Houle',
  'Islet',
  'Jade',
  'Karst',
  'Lande',
  'Mistral',
  'Nacre',
  'Ombre',
  'Pollen',
  'Quartz',
  'Rivage',
  'Sillage',
  'Tuile',
  'Vigie',
  'Zenith',
]
const OWNERS = ['Xavier', 'Nadia', 'Louis', 'Emma']

const DATA = NAMES.map((name, index) => ({
  name,
  owner: OWNERS[index % OWNERS.length],
  status: index % 3 === 0 ? 'Archived' : 'Active',
  commits: ((index + 3) * 37) % 500,
}))

type Project = (typeof DATA)[number]

const rows = ref<Project[]>([])
const total = ref(0)
const loading = ref(true)

/* Simulate the server response; production code would fetch these rows. */
function load(params: DataTableParams) {
  loading.value = true

  window.setTimeout(() => {
    const term = params.search.trim().toLowerCase()
    const matching = term
      ? DATA.filter((row) => `${row.name} ${row.owner} ${row.status}`.toLowerCase().includes(term))
      : DATA

    const key = params.sortKey as keyof Project | null
    const sorted = key
      ? [...matching].sort(
          (a, b) =>
            String(a[key]).localeCompare(String(b[key]), 'en', { numeric: true }) *
            (params.sortDirection === 'desc' ? -1 : 1),
        )
      : matching

    const size = params.perPage ?? sorted.length
    const start = (params.page - 1) * size

    rows.value = sorted.slice(start, start + size)
    total.value = sorted.length
    loading.value = false
  }, 600)
}

onMounted(() => load({ page: 1, perPage: 5, sortKey: null, sortDirection: null, search: '' }))
</script>

<template>
  <VDataTable
    server-side
    variant="outline"
    :columns="columns"
    :rows="rows"
    :total="total"
    :loading="loading"
    row-key="name"
    title="Projects"
    searchable
    :per-page="5"
    :per-page-options="[5, 10]"
    show-range
    @update:params="load"
  />
</template>

Long tables

virtual renders only the rows near the visible part of the table, for tables of thousands of rows. Like stickyHeader, it needs a bounded height. Rows are measured as they render, and the heading checkbox still takes every row.

vue
Ten thousand projects
Owner
Project 1Xavier111
Project 2Nadia148
Project 3Louis185
Project 4Emma222
Project 5Xavier259
Project 6Nadia296
Project 7Louis333
Project 8Emma370
Project 9Xavier407
Project 10Nadia444
Project 11Louis481
Project 12Emma18
Project 13Xavier55
Project 14Nadia92
Project 15Louis129
Project 16Emma166
Project 17Xavier203
Project 18Nadia240
Project 19Louis277
Project 20Emma314
<script setup lang="ts">
import { ref } from 'vue'
import { VDataTable, type DataTableRowId } from 'vectis-ui'

const columns = [
  { key: 'name', label: 'Project', sortable: true },
  { key: 'owner', label: 'Owner' },
  { key: 'commits', label: 'Commits', sortable: true, align: 'end' as const },
]

const OWNERS = ['Xavier', 'Nadia', 'Louis', 'Emma']

const rows = Array.from({ length: 10000 }, (_, index) => ({
  id: index + 1,
  name: `Project ${index + 1}`,
  owner: OWNERS[index % OWNERS.length],
  commits: ((index + 3) * 37) % 500,
}))

const selected = ref<DataTableRowId[]>([])
</script>

<template>
  <VDataTable
    v-model:selected="selected"
    virtual
    sticky-header
    selectable
    variant="outline"
    :height="400"
    :columns="columns"
    :rows="rows"
    row-key="id"
    title="Ten thousand projects"
  />
</template>

Infinite scroll

hasMore emits load-more as the end of the rows comes into view. Append the next rows to rows; while loading, the rows already there stay on show.

vue
Activity
EventAuthor
Event 1Xavier
Event 2Nadia
Event 3Louis
Event 4Emma
Event 5Xavier
Event 6Nadia
Event 7Louis
Event 8Emma
Event 9Xavier
Event 10Nadia
Event 11Louis
Event 12Emma
Event 13Xavier
Event 14Nadia
Event 15Louis
Event 16Emma
Event 17Xavier
Event 18Nadia
Event 19Louis
Event 20Emma
<script setup lang="ts">
import { computed, ref } from 'vue'
import { VDataTable } from 'vectis-ui'

const columns = [
  { key: 'name', label: 'Event' },
  { key: 'owner', label: 'Author' },
]

const OWNERS = ['Xavier', 'Nadia', 'Louis', 'Emma']
const TOTAL = 150

function page(from: number) {
  return Array.from({ length: 30 }, (_, i) => ({
    id: from + i + 1,
    name: `Event ${from + i + 1}`,
    owner: OWNERS[(from + i) % OWNERS.length],
  }))
}

const rows = ref(page(0))
const loading = ref(false)
const hasMore = computed(() => rows.value.length < TOTAL)

// Stands in for a request to your API.
function loadMore() {
  loading.value = true
  setTimeout(() => {
    rows.value = [...rows.value, ...page(rows.value.length)]
    loading.value = false
  }, 600)
}
</script>

<template>
  <VDataTable
    virtual
    sticky-header
    variant="outline"
    :height="360"
    :columns="columns"
    :rows="rows"
    row-key="id"
    :loading="loading"
    :has-more="hasMore"
    title="Activity"
    @load-more="loadMore"
  />
</template>

Loading and empty

Loading takes precedence over empty results. Customize these states with loadingText, emptyText or their slots.

vue
Loading
ProjectOwnerCommits
Loading data…
Nothing to show
ProjectOwnerCommits

No project yet

<script setup lang="ts">
import { VDataTable } from 'vectis-ui'

const columns = [
  { key: 'name', label: 'Project' },
  { key: 'owner', label: 'Owner' },
  { key: 'commits', label: 'Commits', align: 'end' as const },
]
</script>

<template>
  <div class="stack">
    <VDataTable loading variant="outline" :columns="columns" :rows="[]" title="Loading" />

    <VDataTable
      variant="outline"
      :columns="columns"
      :rows="[]"
      empty-text="No project yet"
      title="Nothing to show"
    />
  </div>
</template>

<style scoped>
.stack {
  display: grid;
  gap: var(--vectis-space-6);
}
</style>

A complete table

Combines search, sorting, selection, custom cells and pagination.

vue
Projects

Every project in the organisation

Vectis Xavier DarmetArchived111
Atlas Nadia RousseauActive148
Brume Louis FabreActive185
Granit Emma LefortArchived222
Éclair Xavier DarmetActive259
Falaise Nadia RousseauActive296
Givre Louis FabreArchived333
Houle Emma LefortActive370
<script setup lang="ts">
import { ref } from 'vue'
import { VAvatar, VChip, VDataTable, type DataTableRowId } from 'vectis-ui'

const columns = [
  { key: 'name', label: 'Project', sortable: true },
  { key: 'owner', label: 'Owner', sortable: true },
  { key: 'status', label: 'Status', sortable: true },
  { key: 'commits', label: 'Commits', sortable: true, align: 'end' as const },
]

const NAMES = [
  'Vectis',
  'Atlas',
  'Brume',
  'Granit',
  'Éclair',
  'Falaise',
  'Givre',
  'Houle',
  'Islet',
  'Jade',
  'Karst',
  'Lande',
  'Mistral',
  'Nacre',
  'Ombre',
  'Pollen',
  'Quartz',
  'Rivage',
  'Sillage',
  'Tuile',
  'Vigie',
  'Zenith',
]
const OWNERS = ['Xavier Darmet', 'Nadia Rousseau', 'Louis Fabre', 'Emma Lefort']

const rows = NAMES.map((name, index) => ({
  name,
  owner: OWNERS[index % OWNERS.length],
  status: index % 3 === 0 ? 'Archived' : 'Active',
  commits: ((index + 3) * 37) % 500,
}))

type Project = (typeof rows)[number]

const selected = ref<DataTableRowId[]>([])
const numbers = new Intl.NumberFormat('en-GB')

const selectRowLabel = (row: Project) => `Select ${row.name}`
const selectionText = (count: number) => `${count} project${count > 1 ? 's' : ''} selected`
</script>

<template>
  <VDataTable
    v-model:selected="selected"
    variant="outline"
    :columns="columns"
    :rows="rows"
    row-key="name"
    title="Projects"
    subtitle="Every project in the organisation"
    searchable
    search-placeholder="Search projects"
    selectable
    :select-row-label="selectRowLabel"
    :selection-text="selectionText"
    sticky-header
    :height="420"
    :per-page="8"
    :per-page-options="[8, 16, 24]"
    show-range
  >
    <template #cell-owner="{ row }">
      <span class="owner">
        <VAvatar :name="row.owner" size="xs" />
        {{ row.owner }}
      </span>
    </template>

    <template #cell-status="{ row }">
      <VChip :tone="row.status === 'Active' ? 'success' : 'neutral'" size="xs">
        {{ row.status }}
      </VChip>
    </template>

    <template #cell-commits="{ row }">
      <span class="figure">{{ numbers.format(row.commits) }}</span>
    </template>
  </VDataTable>
</template>

<style scoped>
.owner {
  display: inline-flex;
  align-items: center;
  gap: var(--vectis-space-2);
}
.figure {
  font-variant-numeric: tabular-nums;
}
</style>

API

Props

PropTypeDefault
columnsDataTableColumn[]none
Columns in display order.
rowsRow[]none
Rows to display.
rowKeystringnone
Stable row identifier field. Required for selection; otherwise row position is used.
variantDataTableVariant'flat' | 'outline' | 'elevated' | 'filled''flat'
Unframed rows, or framed by a border, a shadow or a muted fill.
loadingbooleanfalse
Displays loading content instead of rows.
loadingTextstringnone
Visible loading text. Defaults to the dictionary.
emptyTextstringnone
Title of the VEmptyState shown for empty results. Defaults to the dictionary, which distinguishes no data from a search without results.
titlestringnone
Header title. Also names the table, unless the header slot replaces it.
subtitlestringnone
Line under the title. Also describes the table for assistive technology.
searchablebooleanfalse
Adds a search field to the header.
searchPlaceholderstringnone
Search placeholder. Defaults to the dictionary.
searchLabelstringnone
Accessible search field name. Defaults to the dictionary.
searchDebouncenumber250
Server search delay in milliseconds. 0 requests immediately.
stripedbooleanfalse
Tints alternate rows.
stickyHeaderbooleanfalse
Keeps headings visible while scrolling. Requires a bounded height.
heightnumber | stringnone
Whole component height. Numbers use pixels; strings use CSS lengths. Otherwise inherits a constrained parent height.
sortIconIconSourceswap_vert
Icon of an unsorted sortable column.
sortAscIconIconSourcearrow_downward
Ascending sort icon.
sortDescIconIconSourcearrow_upward
Descending sort icon.
perPageOptionsnumber[]none
Page sizes offered in the footer.
perPageTextstringnone
Page-size control label. Defaults to the dictionary.
totalnumbernone
Total server row count for pagination and range display.
showRangebooleanfalse
Displays the visible row range in the footer.
rangeText(range: DataTableRange) => stringnone
Function formatting { start, end, total }. Defaults to the dictionary.
selectablebooleanfalse
Adds row checkboxes and a visible-page checkbox.
selectAllLabelstringnone
Accessible page-selection name. Defaults to the dictionary.
selectionText(count: number) => stringnone
Function formatting the selected count. Defaults to the dictionary; empty with no selection.
selectRowLabel(row: Row, index: number) => stringnone
Function naming each checkbox from its row and global zero-based index. Defaults to a row number.
serverSidebooleanfalse
Delegates search, sort and pagination to the server through update:params.
virtualbooleanfalse
Renders only the rows near the visible part of the table. Needs a bounded height; rows then carry aria-rowindex.
hasMorebooleanfalse
Emits load-more as the end of the rows comes into view. The rows stay on show while loading.
v-model:sortDataTableSort | nullnull
Sort key and direction, or null. Changing sort preserves the page.
v-model:pagenumber1
Page number from 1. Search and page-size changes reset it to 1. Out-of-range values display the nearest page without rewriting the model.
v-model:perPagenumbernone
Rows per page. Values above 0 enable pagination.
v-model:selectedDataTableRowId[][]
Selected rowKey identifiers, preserved across pages. The header checkbox covers the rows of the page shown, rendered or not.
v-model:searchstring''
Search query. Local search ignores case and accents; server mode reports it without filtering.

Events

EventType
load-more[]
The end of the rows came into view while hasMore is set: append the next rows.
update:params[params: DataTableParams]
Server-mode query changes: search, sort, page and page size. Does not fire on mount or for unchanged values.

Slots

SlotType
header{}
Content replacing the title and subtitle. The search stays beside it; name the table with aria-label.
toolbar{}
Row between the header and the table, for actions and filters.
loading{}
Content replacing the loading spinner and text.
emptyDataTableEmptySlotProps
Empty-result content, replacing the default VEmptyState. Receives the current search.

Types

Types used in the API tables. Import exported types from vectis-ui.

export interface BuiltinIcon {
  name: string
  paths: readonly [string] | readonly [string, string]
}
export interface DataTableColumn {
  key: string
  label: string
  sortable?: boolean
  align?: DataTableColumnAlign
}
export type DataTableColumnAlign = 'start' | 'center' | 'end'
export interface DataTableEmptySlotProps {
  search: string
}
export interface DataTableParams {
  page: number
  perPage: number | null
  sortKey: string | null
  sortDirection: DataTableSortDirection | null
  search: string
}
export interface DataTableRange {
  start: number
  end: number
  total: number
}
export type DataTableRowId = string | number
export interface DataTableSort {
  key: string
  direction: DataTableSortDirection
}
export type DataTableSortDirection = 'asc' | 'desc'
export type IconRender =
  | { path: string; viewBox?: string }
  | { component: Component; props?: Record<string, unknown> }
  | { src: string }
  | { text: string; class?: string }
  | { class: string }
export type IconSource = string | BuiltinIcon | IconRender

CSS variables

TokenValue
--vectis-control-size-table-search16rem