vael-ui v0.5.7

Data display

Layout

DataTable

A data grid with sorting, selection, column resizing and virtualization, built from Column components. Use it for records people sort, select and compare.

For hundreds of rows, add virtualize and a scroll-height, such as scroll-height="400px". The table then draws only the rows in view, so sorting, selecting and scrolling stay fast. Past 150 rendered rows, rows also stop sliding into place as they sort.

Install

import { DataTable } from 'vael-ui'

Playground

Expand row

Placement, behaviour and animation

Usage
<script setup lang="ts">
import { DataTable, Column } from 'vael-ui'

const rows = [
  { id: 'r1', name: 'Mira Mitchell', role: 'Engineer', status: 'Active' },
  { id: 'r2', name: "Marcus O'Connor", role: 'Designer', status: 'Active' },
  { id: 'r3', name: 'Priya Nair', role: 'Product Manager', status: 'Invited' },
]
</script>

<template>
  <DataTable :data="rows" row-key="id">
    <template #columns="{ columnData }">
      <Column :data="columnData" field="name" label="Name" />
      <Column :data="columnData" field="role" label="Role" />
      <Column :data="columnData" field="status" label="Status" />
    </template>
  </DataTable>
</template>

Props

NameTypeDefaultDescription
dataRequiredT[]Row objects. Each <Column> reads its content from them by field.
rowKeyRequiredkeyof T | ((row: T) => string | number)Stable row identity: a key on T, or a function for composite or derived keys.
loadingbooleanfalseShows the #loading slot instead of the rows or empty state.
selectablebooleanfalseAdds a leading checkbox or radio column that tracks the selection.
selectionMode'checkbox' | 'row''checkbox''checkbox' adds a selection column. 'row' selects on row click, with arrow-key navigation.
singlebooleanfalseLimits selection to one row, with Radio buttons in 'checkbox' mode.
scrollHeightstringCSS length, such as '400px' or '60vh'. When set, the body scrolls under a sticky header.
stackedBreakpointstringCSS length, such as '640px'. Below this viewport width, rows switch to a stacked card layout.
size'sm' | 'md' | 'lg''md'Row-density variant.
stripedRowsbooleanfalseAlternates row backgrounds. Selected and hover backgrounds win over stripes.
showGridlinesbooleanfalseAdds an inline-end border to every cell.
resizableColumnsbooleanfalseAdds a drag handle to every column header's edge for resizing.
frozenColumnsnumber0Pins the first N columns to the left while the table scrolls horizontally.
scrollFadebooleantrueFades the edges that have more to scroll to, so it's clear the table scrolls.
rowsnumberRows per page. Pair it with v-model:page. Unset, all rows render.
manualSortbooleanfalseMarks data as sorted on the server; a header click only updates v-model:sort.
lazybooleanfalseMarks data as the current page only. Pair it with total.
totalnumberRow count across all pages. Only used with lazy; unset, it falls back to data.length.
virtualizeboolean | { itemSize?: number | undefined; overscan?: number | undefined; estimateSize?: number | undefined; }Renders only the visible rows. Requires scrollHeight. itemSize fixes the row height.
motionDataTableMotiontruePlays the built-in row and column-drag transitions; false changes them at once. An object animates the rows your way: values for the row part, or enter / leave hooks for your own library. Past 150 rows, changes are instant either way.
reorderableColumnsbooleanfalseLets you drag column headers to reorder them. Pair with v-model:columnOrder.
columnGripVisibility'hover' | 'always''always'When a reorderable column's drag grip shows: 'always', or only on hover and focus ('hover').
canDrop((details: SortableDropDetails) => boolean)Runs while a column drags; return false to mark the target invalid.
beforeDrop((details: SortableDropDetails) => boolean | Promise<boolean>)Async check before a column drop. Return false, or a promise of it, to cancel.
previewMode'element' | 'clone''clone'What follows the pointer in a column drag. Avoid 'element' here.
touchDragDelaynumber150Ms a touch must hold a header before a column drag starts, so taps still sort.
uiPartial<Record<'root' | 'toolbar' | 'table' | 'thead' | 'th' | 'sortButton' | 'sortChevron' | 'grip' | 'resizeHandle' | 'tbody' | 'tr' | 'td' | 'expansionRow' | 'expansionContent' | 'expandChevron' | 'footer', UiPartValue>>Class and style overrides for each part.
pagenumber1Current page, 1-based. Only used when rows is set; DataTable clamps it to the page count.
sort{ field: keyof T | null; dir: "asc" | "desc" | null; }{ field: null, dir: null }Current sort field and direction.
columnOrder(keyof T)[][]Column fields in display order. When empty, columns follow their <Column> order in the template.

Events

NameTypeDescription
reach-end()Virtualized only: fires near the end of data, to fetch the next page.
update:selection(rows: T[])Fires when the selection changes, with the resolved row objects (not raw keys).
row-click(row: T)Fires when you click a row anywhere outside its interactive descendants.
reach-start()Virtualized only: fires when the rendered window nears the start of data, so you can fetch the previous page.
column-reorder(order: (keyof T)[])Fires when a column drag commits, with the new field order.
drop-error(error: unknown, details: SortableDropDetails)Fires when beforeDrop throws or rejects during a column reorder, after DataTable reverts the move.
update:page(value: number)Fires when page changes (v-model:page).
update:sort(value: { field: keyof T | null; dir: "asc" | "desc" | null; })Fires when sort changes (v-model:sort).
update:columnOrder(value: (keyof T)[])Fires when columnOrder changes (v-model:columnOrder).

Slots

NameTypeDescription
columns{ Column: TypedColumn; columnData: T[]; }Declares <Column> children. columnData is the table's :data, passed back for type inference.
toolbar{ selected: Set<string | number>; count: number; }Toolbar content (search, bulk actions, …).
loadinganyReplaces the row area while loading is true.
emptyanyReplaces the row area when data is empty and not loading.
expansion{ row: T; }Full-width row beneath an expanded row. In stacked mode, it always renders, with no toggle.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
highlightElHTMLElement | nullThe hover and keyboard highlight, sliding between body rows. With motion: false it moves at once, for your own animation.

Motion New

DataTable's body rows: values or hooks for row, and the list's stagger.

<DataTable
  :motion="{ initial: { row: { opacity: 0, y: 8 } }, stagger: 0.04 }"
/>
NameTypeDescription
initialexitrowSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
staggerleavingappearnumber | 'pop' | 'hold' | booleanItems coming in together start stagger seconds apart. A leaving item lifts out so the rest close the gap ('pop'), or keeps its space until it's gone ('hold'). appear: true also brings in the items already there when it mounts.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

Follows the Table pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
EnterSpaceCycles a sortable column through ascending, descending and unsorted, from its header button.
ArrowDownArrowUpMoves focus to the next or previous row, with selectionMode="row".
HomeEndMoves focus to the first or last row, with selectionMode="row".
SpaceSelects or clears the focused row, with selectionMode="row".
EnterSelects or clears the focused row and fires row-click, with selectionMode="row".
ShiftArrowDownShiftArrowUpAdds the focused row and the next or previous row to the selection, unless single is set.
EnterSpaceShows or hides a row's expansion, from its expand button.
ArrowLeftArrowRightNarrows or widens the column by 16 px, from its focused resize handle.
AltArrowLeftAltArrowRightMoves a reorderable column one place, from its header.
  • The sorted column header sets aria-sort to ascending or descending, and each sortable header label is a <button>. A header click announces the new sort through a polite status region. The expand button has aria-expanded, and aria-controls while open.
  • With row selection, the table is a role="grid" and rows carry aria-selected. With selectionMode="row", rows are one Tab stop with a roving tabindex, and keys inside a cell’s own controls stay with them. In checkbox mode, each row’s Checkbox (a Radio with single) is named after its row, such as “Select row Alice”.
  • Resize handles are focusable role="separator" elements. An always-mounted role="status" region announces new column widths and positions, and reads “Loading…” while loading sets aria-busy.
  • With scrollHeight, the head and body are separate tables, so ARIA roles rebuild one table for screen readers. Right to left, ArrowLeft and ArrowRight swap.