DataTable
DataTable is a headless, generic table built on @tanstack/vue-table v9, styled with the same primitives as Table. You describe your rows with column definitions, and it renders sortable headers, an optional expansion row, a loading state, and an empty state.
<script setup lang="ts">
import { createColumnHelper } from '@tanstack/vue-table'
import { DataTable, type DataTableFeatures } from '@myghf/ui'
const data = [
{ id: 'r1', patient: 'Amina Farouk', waiting: 3 },
]
const columnHelper = createColumnHelper<DataTableFeatures, (typeof data)[number]>()
const columns = columnHelper.columns([
columnHelper.accessor('patient', { header: 'Patient' }),
columnHelper.accessor('waiting', { header: 'Waiting (days)' }),
])
const getRowId = (row: (typeof data)[number]) => row.id
</script>
<template>
<DataTable :data="data" :columns="columns" :get-row-id="getRowId" />
</template>Examples
Sorting
Click a header to sort by that column; click again to reverse. By default the sort lives in the component and is reported through update:sorting. Bind v-model:sorting to own the state in the parent instead — the component then only sorts when you write the prop back, which is what a server-side sort (manual) needs. Set sortable to false to make every header static.
| Amina Farouk | Cardiology | 3 |
| Youssef Kamal | Radiology | 12 |
| Layla Hassan | Oncology | 1 |
| Omar Said | Cardiology | 7 |
Sorted by: the original order
<script setup lang="ts">
import { ref } from 'vue'
import { createColumnHelper } from '@tanstack/vue-table'
import { DataTable, type DataTableFeatures } from '@myghf/ui'
interface Referral {
id: string
patient: string
clinic: string
waiting: number
}
const referrals: Referral[] = [
{ id: 'r1', patient: 'Amina Farouk', clinic: 'Cardiology', waiting: 3 },
{ id: 'r2', patient: 'Youssef Kamal', clinic: 'Radiology', waiting: 12 },
{ id: 'r3', patient: 'Layla Hassan', clinic: 'Oncology', waiting: 1 },
{ id: 'r4', patient: 'Omar Said', clinic: 'Cardiology', waiting: 7 },
]
const columnHelper = createColumnHelper<DataTableFeatures, Referral>()
const columns = columnHelper.columns([
columnHelper.accessor('patient', { header: 'Patient' }),
columnHelper.accessor('clinic', { header: 'Clinic' }),
columnHelper.accessor('waiting', { header: 'Waiting (days)' }),
])
const getRowId = (row: Referral) => row.id
const sorting = ref<{ id: string; desc: boolean }[]>([])
</script>
<template>
<div class="space-y-3">
<DataTable
:data="referrals"
:columns="columns"
:get-row-id="getRowId"
:sortable="true"
@update:sorting="sorting = $event"
/>
<p class="text-sm text-muted">
Sorted by:
{{
sorting.length
? sorting.map((s) => `${s.id} ${s.desc ? 'descending' : 'ascending'}`).join(', ')
: 'the original order'
}}
</p>
</div>
</template>Expanding rows and cell slots
With expandable, clicking a row toggles an expansion row rendered through the expansion slot. Expansion is single-row (opening one closes the other). Use a cell-<columnId> slot to override a column's cell — here the status column renders a Tag.
| Toggle row | ||
|---|---|---|
| Amina Farouk | Ready | |
| Youssef Kamal | Pending | |
| Layla Hassan | Ready |
<script setup lang="ts">
import { ref } from 'vue'
import { createColumnHelper } from '@tanstack/vue-table'
import { DataTable, Tag, type DataTableFeatures } from '@myghf/ui'
interface Order {
id: string
patient: string
status: 'Ready' | 'Pending'
notes: string
}
const orders: Order[] = [
{ id: 'o1', patient: 'Amina Farouk', status: 'Ready', notes: 'Consent signed; slot booked for Thursday.' },
{ id: 'o2', patient: 'Youssef Kamal', status: 'Pending', notes: 'Awaiting the radiology report.' },
{ id: 'o3', patient: 'Layla Hassan', status: 'Ready', notes: 'Pre-op bloods completed.' },
]
const columnHelper = createColumnHelper<DataTableFeatures, Order>()
const columns = columnHelper.columns([
columnHelper.accessor('patient', { header: 'Patient' }),
columnHelper.accessor('status', { header: 'Status' }),
])
const getRowId = (row: Order) => row.id
const expanded = ref<Record<string, boolean>>({})
</script>
<template>
<DataTable
v-model:expanded="expanded"
:data="orders"
:columns="columns"
:get-row-id="getRowId"
expandable
empty-label="No orders"
>
<template #cell-status="{ value }">
<Tag :tone="value === 'Ready' ? 'success' : 'warning'">{{ value }}</Tag>
</template>
<template #expansion="{ row }">
<p class="text-sm text-muted">{{ row.original.notes }}</p>
</template>
</DataTable>
</template>Loading
Set loading while data is in flight and DataTable replaces the body with loadingRows placeholder rows (default 5), each a Skeleton per column, while keeping the real header. The wrapper gets aria-busy="true" and a screen-reader-only loadingLabel (default Loading…) announces the status. The empty state is suppressed while loading, so an empty data array does not flash "No results" before the rows arrive.
<script setup lang="ts">
import { ref } from 'vue'
import { createColumnHelper } from '@tanstack/vue-table'
import { Button, DataTable, type DataTableFeatures } from '@myghf/ui'
interface Referral {
id: string
patient: string
clinic: string
waiting: number
}
const referrals: Referral[] = [
{ id: 'r1', patient: 'Amina Farouk', clinic: 'Cardiology', waiting: 3 },
{ id: 'r2', patient: 'Youssef Kamal', clinic: 'Radiology', waiting: 12 },
{ id: 'r3', patient: 'Layla Hassan', clinic: 'Oncology', waiting: 1 },
]
const columnHelper = createColumnHelper<DataTableFeatures, Referral>()
const columns = columnHelper.columns([
columnHelper.accessor('patient', { header: 'Patient' }),
columnHelper.accessor('clinic', { header: 'Clinic' }),
columnHelper.accessor('waiting', { header: 'Waiting (days)' }),
])
const getRowId = (row: Referral) => row.id
const loading = ref(true)
</script>
<template>
<div class="space-y-3">
<DataTable
:data="referrals"
:columns="columns"
:get-row-id="getRowId"
:loading="loading"
:loading-rows="3"
loading-label="Loading referrals"
/>
<Button variant="outline" size="sm" @click="loading = !loading">
{{ loading ? 'Finish loading' : 'Reload' }}
</Button>
</div>
</template>Types
Row selection and bulk actions
Set selectable and bind v-model:selection to a map keyed by row id (provide getRowId so the keys are stable). A leading checkbox column appears; the header checkbox selects every row, and a bulk-actions bar is shown while rows are selected. Fill it through the bulk-actions slot, which receives the selected rows and a clear function. Pair it with toCsv + downloadCsv to export the selection — the demo's Export button does exactly that.
Selection is controlled. DataTable owns no selection state of its own: every toggle emits update:selection with the complete new map, and the parent writes it back. Keep the map accumulated across pages, filters, and sorts — carry the previous map forward (merge the toggle) rather than replacing it with only the visible rows, or earlier selections are lost. The "preserves earlier-page selections in server-side mode" test pins this.
manual mode is page-scoped. With manual (server-side data), the header checkbox and toggleAllRowsSelected operate on the rows in the current page — the row model — not on every matching record. To offer "select all N records", track that intent in the parent (for example a selectAll flag sent to the server) rather than relying on the checkbox.
| Amina Farouk | Cardiology | |
| Youssef Kamal | Neurology | |
| Salma Nabil | Oncology |
<script setup lang="ts">
import { computed, ref } from 'vue'
import { createColumnHelper } from '@tanstack/vue-table'
import { Button, DataTable, downloadCsv, toCsv, type DataTableFeatures } from '@myghf/ui'
interface Referral {
id: string
patient: string
unit: string
}
const data: Referral[] = [
{ id: 'r1', patient: 'Amina Farouk', unit: 'Cardiology' },
{ id: 'r2', patient: 'Youssef Kamal', unit: 'Neurology' },
{ id: 'r3', patient: 'Salma Nabil', unit: 'Oncology' },
]
const columnHelper = createColumnHelper<DataTableFeatures, Referral>()
const columns = columnHelper.columns([
columnHelper.accessor('patient', { header: 'Patient' }),
columnHelper.accessor('unit', { header: 'Unit' }),
])
const getRowId = (row: Referral) => row.id
const selection = ref<Record<string, boolean>>({})
const selectedRecords = computed(() => data.filter((row) => selection.value[row.id]))
function exportSelection() {
const csv = toCsv<Referral>(
[
{ id: 'patient', header: 'Patient' },
{ id: 'unit', header: 'Unit' },
],
selectedRecords.value,
)
downloadCsv('referrals.csv', csv)
}
</script>
<template>
<DataTable
v-model:selection="selection"
:data="data"
:columns="columns"
:get-row-id="getRowId"
selectable
>
<template #bulk-actions="{ rows, clear }">
<Button size="sm" variant="outline" @click="clear">Clear</Button>
<Button size="sm" variant="outline" @click="exportSelection">Export</Button>
<Button size="sm">Archive {{ rows.length }}</Button>
</template>
</DataTable>
</template>Error state
Set error to a message and DataTable replaces the body with it (use the error slot for custom content). The loading state still wins while loading is true.
Searching and filters
searchable renders a global search input, bound with v-model:global-filter. Per-column filters are a ColumnFiltersState bound with v-model:filters — every active filter shows as a removable chip in the toolbar, with a Clear filters button. When rows are filtered out the empty state switches to noResultsLabel. Use the toolbar slot to add your own controls (e.g. a per-column filter select).
- Unit: Cardiology
| Amina Farouk | Cardiology |
| Salma Nabil | Cardiology |
<script setup lang="ts">
import { ref } from 'vue'
import { createColumnHelper, type ColumnFiltersState } from '@tanstack/vue-table'
import { DataTable, type DataTableFeatures } from '@myghf/ui'
interface Referral {
id: string
patient: string
unit: string
}
const data: Referral[] = [
{ id: 'r1', patient: 'Amina Farouk', unit: 'Cardiology' },
{ id: 'r2', patient: 'Youssef Kamal', unit: 'Neurology' },
{ id: 'r3', patient: 'Salma Nabil', unit: 'Cardiology' },
{ id: 'r4', patient: 'Omar Hatem', unit: 'Oncology' },
]
const columnHelper = createColumnHelper<DataTableFeatures, Referral>()
const columns = columnHelper.columns([
columnHelper.accessor('patient', { header: 'Patient' }),
columnHelper.accessor('unit', { header: 'Unit' }),
])
const getRowId = (row: Referral) => row.id
const globalFilter = ref('')
const filters = ref<ColumnFiltersState>([{ id: 'unit', value: 'Cardiology' }])
</script>
<template>
<DataTable
v-model:global-filter="globalFilter"
v-model:filters="filters"
:data="data"
:columns="columns"
:get-row-id="getRowId"
searchable
search-placeholder="Search patients…"
/>
</template>Column visibility, order, pinning, and resizing
Three pieces of column state are bound with v-model: column-visibility (id → visible), column-order (ids), and column-pinning ({ start, end }, logical so it mirrors under RTL — pinned cells stick with inset-inline-start/inset-inline-end). Set resizable to show drag handles on each header. Build the controls in the toolbar slot (the demo toggles a column and pins another).
| Amina Farouk | Cardiology | 3 |
| Youssef Kamal | Neurology | 12 |
| Salma Nabil | Oncology | 7 |
<script setup lang="ts">
import { ref } from 'vue'
import { createColumnHelper, type ColumnPinningState } from '@tanstack/vue-table'
import { Checkbox, DataTable, type DataTableFeatures } from '@myghf/ui'
interface Referral {
id: string
patient: string
unit: string
waiting: number
}
const data: Referral[] = [
{ id: 'r1', patient: 'Amina Farouk', unit: 'Cardiology', waiting: 3 },
{ id: 'r2', patient: 'Youssef Kamal', unit: 'Neurology', waiting: 12 },
{ id: 'r3', patient: 'Salma Nabil', unit: 'Oncology', waiting: 7 },
]
const columnHelper = createColumnHelper<DataTableFeatures, Referral>()
const columns = columnHelper.columns([
columnHelper.accessor('patient', { header: 'Patient', size: 200 }),
columnHelper.accessor('unit', { header: 'Unit', size: 160 }),
columnHelper.accessor('waiting', { header: 'Waiting (days)', size: 140, meta: { align: 'end' } }),
])
const getRowId = (row: Referral) => row.id
const visibility = ref<Record<string, boolean>>({})
const pinning = ref<ColumnPinningState>({ start: [], end: [] })
</script>
<template>
<DataTable
v-model:column-visibility="visibility"
v-model:column-pinning="pinning"
:data="data"
:columns="columns"
:get-row-id="getRowId"
resizable
>
<template #toolbar>
<label class="flex items-center gap-1.5 text-xs text-muted">
<Checkbox
:model-value="visibility.waiting !== false"
@update:model-value="(value) => (visibility.waiting = Boolean(value))"
/>
Waiting column
</label>
<label class="flex items-center gap-1.5 text-xs text-muted">
<Checkbox
:model-value="pinning.start?.includes('patient') ?? false"
@update:model-value="(value) => (pinning.start = value ? ['patient'] : [])"
/>
Pin patient
</label>
</template>
</DataTable>
</template>Responsive columns
Give a column meta: { hideBelow } and it hides while the viewport is narrower than that screen — Tailwind semantics, so hideBelow: 'md' hides below 768px:
columnHelper.accessor('waiting', {
header: 'Waiting (days)',
meta: { hideBelow: 'md' }, // 'sm' | 'md' | 'lg' | 'xl' | '2xl'
})The breakpoint never writes into v-model:column-visibility: viewport hiding is merged inside the table, and update:columnVisibility reports only your own changes. Above the breakpoint (e.g. desktop, and the first SSR render, where width is unknown until mount) every column is normal again. Columns you already hid through column-visibility are not surfaced by the breakpoint.
Below the breakpoint the hidden values stay reachable through a row disclosure: each row gains the leading expander button — the same one expandable renders, labelled with expandRowLabel — and its expansion row lists the hidden columns as a <dl> of labels and values (values go through your cell-<columnId> slots when present). With expandable set, the list renders above your expansion slot content in the same row.
meta key | Type | Description |
|---|---|---|
hideBelow | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | Hide this column while the viewport is narrower than that screen. |
| Amina Farouk | Cardiology | 3 |
| Youssef Kamal | Neurology | 12 |
| Salma Nabil | Oncology | 7 |
<script setup lang="ts">
import { ref } from 'vue'
import { createColumnHelper } from '@tanstack/vue-table'
import { DataTable, type DataTableFeatures } from '@myghf/ui'
interface Referral {
id: string
patient: string
unit: string
waiting: number
}
const data: Referral[] = [
{ id: 'r1', patient: 'Amina Farouk', unit: 'Cardiology', waiting: 3 },
{ id: 'r2', patient: 'Youssef Kamal', unit: 'Neurology', waiting: 12 },
{ id: 'r3', patient: 'Salma Nabil', unit: 'Oncology', waiting: 7 },
]
const columnHelper = createColumnHelper<DataTableFeatures, Referral>()
const columns = columnHelper.columns([
columnHelper.accessor('patient', { header: 'Patient', size: 200 }),
columnHelper.accessor('unit', {
header: 'Unit',
size: 160,
meta: { hideBelow: 'sm' },
}),
columnHelper.accessor('waiting', {
header: 'Waiting (days)',
size: 140,
meta: { hideBelow: 'md' },
}),
])
const getRowId = (row: Referral) => row.id
const expanded = ref<Record<string, boolean>>({})
</script>
<template>
<DataTable
v-model:expanded="expanded"
:data="data"
:columns="columns"
:get-row-id="getRowId"
/>
</template>Resize below 768px to collapse Waiting (days) into the row disclosures, and below 640px to collapse Unit as well.
Header and cell alignment
Set meta.align on a column to align its header and that column's cells. The value maps to logical properties (text-start / text-center / text-end), so it mirrors automatically under RTL:
columnHelper.accessor('waiting', {
header: 'Waiting (days)',
meta: { align: 'end' },
})meta key | Type | Default | Description |
|---|---|---|---|
align | 'start' | 'center' | 'end' | 'start' | Text alignment for the column's header and cells. |
Sortable headers stay clickable when aligned — the sort button lines up with the aligned text. The columns demo end-aligns Waiting (days).
Pagination and server-side mode
Set paginate to render the pagination footer (bound with v-model:page-index / v-model:page-size) over the client-side rows. For large datasets set manual instead: TanStack skips client sorting/filtering/pagination, rowCount supplies the server total, and you refetch on update:pageIndex, update:pageSize, update:sorting, and update:filters. The pagination slot replaces the default footer.
<DataTable
v-model:page-index="pageIndex"
v-model:page-size="pageSize"
:data="rows"
:columns="columns"
:get-row-id="getRowId"
:row-count="total"
manual
/>| Patient 1 | Cardiology |
| Patient 2 | Neurology |
| Patient 3 | Oncology |
| Patient 4 | Paediatrics |
| Patient 5 | Cardiology |
<script setup lang="ts">
import { ref } from 'vue'
import { createColumnHelper } from '@tanstack/vue-table'
import { DataTable, type DataTableFeatures } from '@myghf/ui'
interface Referral {
id: string
patient: string
unit: string
}
const units = ['Cardiology', 'Neurology', 'Oncology', 'Paediatrics']
const data: Referral[] = Array.from({ length: 12 }, (_, index) => ({
id: `r${index + 1}`,
patient: `Patient ${index + 1}`,
unit: units[index % units.length],
}))
const columnHelper = createColumnHelper<DataTableFeatures, Referral>()
const columns = columnHelper.columns([
columnHelper.accessor('patient', { header: 'Patient' }),
columnHelper.accessor('unit', { header: 'Unit' }),
])
const getRowId = (row: Referral) => row.id
const pageIndex = ref(0)
const pageSize = ref(5)
</script>
<template>
<DataTable
v-model:page-index="pageIndex"
v-model:page-size="pageSize"
:data="data"
:columns="columns"
:get-row-id="getRowId"
paginate
/>
</template>Virtual scrolling
For very large datasets set maxHeight and virtual together: DataTable renders only the visible slice (plus a small overscan) and pads the rest with spacer rows, so the DOM stays small however many rows you pass. It assumes a uniform rowHeight (default 40) and does not account for expansion rows, so use it with flat rows.
<DataTable :data="rows" :columns="columns" :get-row-id="getRowId" max-height="24rem" virtual />DataTableFeatures
columns is typed against DataTableFeatures, the feature set registered in src/lib/table.ts and re-exported from @myghf/ui. It enables exactly three TanStack features:
| Feature | What it adds |
|---|---|
rowSortingFeature (+ sortedRowModel, sortFns) | Sortable columns and the update:sorting state. |
rowPaginationFeature (+ paginatedRowModel) | Pagination state. DataTable renders the footer when paginate (or manual) is set; otherwise reach the row model by composing TanStack directly with DataTableFeatures. |
rowExpandingFeature (+ expandedRowModel) | Per-row expansion driven by the expanded map. |
rowSelectionFeature | Per-row selection, select-all, and the bulk-actions bar. |
columnFilteringFeature (+ filteredRowModel, filterFns) | Per-column filters, the toolbar chips, and update:filters. |
globalFilteringFeature | The global search term and update:globalFilter. |
columnVisibilityFeature | Column visibility and update:columnVisibility. |
columnOrderingFeature | Column order and update:columnOrder. |
columnPinningFeature | Logical start/end pinning and update:columnPinning. |
columnSizingFeature + columnResizingFeature | Column sizes and the drag-to-resize handles. |
TanStack v9 tree-shakes anything not registered, so features outside this list — column grouping — are not available through DataTable. Use it when you need exactly this set; otherwise compose Table yourself.
columns has the type ColumnDef<typeof dataTableFeatures, T>[], so author them with createColumnHelper<DataTableFeatures, T>() from @tanstack/vue-table. A column's numeric size is read structurally and used as the column (header) width. Column meta is typed through the feature set's columnMeta slot — hideBelow (see Responsive columns) and align (see Header and cell alignment), with the DataTableColumnMeta / DataTableHideBelow types exported from @myghf/ui.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
data | T[] | — (required) | Row data. |
columns | ColumnDef<DataTableFeatures, T>[] | — (required) | Column definitions. |
getRowId | (row: T) => string | — | Stable row id, used for keys and the expansion map. Strongly recommended. |
striped | boolean | false | Shades every even body row. |
size | 'sm' | 'default' | 'default' | Compact or default text size. |
emptyLabel | string | 'No results' | Message shown when there are no rows. |
sortable | boolean | true | Renders clicking/sorting headers for columns that can sort. |
sorting | SortingState | — | Active sort. Uncontrolled unless bound — bind with v-model:sorting to own it in the parent. |
expandable | boolean | false | Makes rows toggle a detail row. |
expanded | Record<string, boolean> | {} | Expansion map keyed by row id. Bind with v-model:expanded. |
stopRowToggleOnInteractiveCells | boolean | true | Keeps clicks on buttons/links/inputs from also toggling the row. |
maxHeight | string | — | When set, makes the wrapper scroll vertically at this height. |
loading | boolean | false | Renders placeholder skeleton rows instead of the data rows. Sets aria-busy="true" on the wrapper and suppresses the empty state. |
loadingRows | number | 5 | Number of placeholder rows shown while loading. |
loadingLabel | string | 'Loading…' | Screen-reader-only text announced as the loading status. |
selectable | boolean | false | Renders a leading checkbox column and the bulk-actions bar. |
selection | Record<string, boolean> | {} | Selected-row map keyed by row id. Bind with v-model:selection. |
selectAllLabel | string | 'Select all rows' | Accessible name for the header checkbox. |
selectRowLabel | string | 'Select row' | Accessible-name prefix for each row checkbox (the row number is appended). |
selectedLabel | string | 'selected' | Word following the count in the bulk-actions bar. |
error | string | — | Error message. Replaces the body unless loading is set. |
expandRowLabel | string | 'Toggle row' | Accessible-name prefix for each row's expander button (the row number is appended). |
searchable | boolean | false | Renders a global search input in the toolbar. |
searchPlaceholder | string | 'Search…' | Placeholder for the search input. |
searchLabel | string | 'Search' | Accessible name for the search input. |
globalFilter | string | '' | Global filter term. Bind with v-model:global-filter. |
filters | ColumnFiltersState | [] | Per-column filters. Bind with v-model:filters. |
noResultsLabel | string | 'No results match your filters' | Empty-state text shown while a filter is active. |
clearFiltersLabel | string | 'Clear filters' | Toolbar button that clears all filters. |
columnVisibility | Record<string, boolean> | {} | Column visibility by id. Bind with v-model:column-visibility. |
columnOrder | string[] | [] | Column order (ids). Bind with v-model:column-order. |
columnPinning | { start?: string[]; end?: string[] } | { start: [], end: [] } | Pinned columns (logical). Bind with v-model:column-pinning. |
resizable | boolean | false | Render drag handles to resize columns. |
manual | boolean | false | Server-side mode: skip client sorting/filtering/pagination. |
paginate | boolean | false | Render the pagination footer. |
pageIndex | number | 0 | Current page (0-based). Bind with v-model:page-index. |
pageSize | number | 10 | Rows per page. Bind with v-model:page-size. |
rowCount | number | 0 | Total rows across all pages (server-side). |
pageSizeOptions | number[] | [5, 10, 20] | Page-size choices in the footer. |
virtual | boolean | false | Window the rows (requires maxHeight). Assumes uniform row height. |
rowHeight | number | 40 | Assumed height of one data row, in pixels, when virtual. |
Events
| Event | Payload | Description |
|---|---|---|
update:sorting | { id: string; desc: boolean }[] | Emitted whenever the sort state changes. |
update:expanded | Record<string, boolean> | Emitted with the new expansion map. |
update:selection | Record<string, boolean> | Emitted with the new selection map. |
update:globalFilter | string | Emitted with the new global filter term. |
update:filters | ColumnFiltersState | Emitted with the new per-column filters. |
update:columnVisibility | Record<string, boolean> | Emitted with the new visibility map. Breakpoint-forced hiding (Responsive columns) is merged inside the table and never appears here. |
update:columnOrder | string[] | Emitted with the new column order. |
update:columnPinning | { start?: string[]; end?: string[] } | Emitted with the new pinning state. |
update:pageIndex | number | Emitted when the page changes. |
update:pageSize | number | Emitted when the page size changes. |
row-click | unknown | Emitted with the clicked row's original data. Fires even when expandable is false. |
Slots
| Slot | Props | Description |
|---|---|---|
empty | — | Replaces emptyLabel when there are no rows. |
cell-<columnId> | { row, cell, value } | Overrides that column's cell. The column id is its accessor key (or id). |
expansion | { row } | Content of the expansion row, shown for expanded rows only — after the responsive disclosure list, when one is active. |
bulk-actions | { rows, clear } | Content of the bulk-actions bar, shown while rows are selected. |
error | — | Replaces the error text when error is set. |
toolbar | — | Extra controls in the toolbar (next to the search input and chips). |
pagination | { pageIndex, pageSize, total } | Replaces the default pagination footer. |
DataTable renders no default slot — all cells come from FlexRender or a cell-* slot.
Exposed methods
None. DataTable does not call defineExpose. Sort and expand through v-model bindings and the events above.
Accessibility
- Sortable headers are real
<button>s inside<th>, with thearia-sortstate written by the underlying TableHead. Non-sortable headers render plain text. Keyboard users can focus and activate each sort button. - Expansion is toggled by clicking the row (
TableRowgetsclickableanddata-state="expanded"), and by a leading expander button rendered whenexpandable.stopRowToggleOnInteractiveCellsprevents a click on an interactive cell from also toggling the row. The expander is a real<button>witharia-expandedand anaria-label(expandRowLabelplus the row number), so expansion is keyboard reachable. - With
expandable, the expansion row spans all columns and is revealed inline after the row it belongs to. - While
loading, the wrapper carriesaria-busy="true"and asr-onlyelement holdsloadingLabel, so assistive technology hears a status without seeing the placeholder rows. Placeholder rows are inert — they carry no click handler and cannot expand. - The empty state renders a full-width
TableEmptyrow, so the table keeps its structure when there is no data. It is suppressed whileloading, so an emptydataarray does not flash "No results" before the first rows arrive. - With
selectable, the header and row checkboxes are real Checkbox controls witharia-labels (selectAllLabel, andselectRowLabelplus the row number), andaria-checkedreflects the selection. Clicking them never toggles row expansion. - Responsive columns (see above) reuse that same expander button —
aria-expanded,aria-labelfromexpandRowLabel— so the disclosure is keyboard reachable, and the hidden values render as a semantic<dl>ofdt/ddpairs.
Dark mode & RTL
DataTablerenders through Table, so it inherits the same semantic tokens (bg-surface,border-border,bg-surface-muted) and adapts to dark mode. Expansion rows usebg-surface-muted/30.- Loading placeholders use Skeleton, whose
bg-surface-mutedfill is defined for both themes, so the loading state needs no extra dark-mode styles. - Sorting icons are Lucide chevrons, and the width is applied per column, so no physical direction is baked in. When
maxHeightis set the wrapper adds anoverflow-autoscroll region; the underlying table's logicaltext-start/text-endalignment mirrors correctly underdir="rtl".
