Data Table
Table of your data on TanStack Table v8, with sorting, pagination, filtering, row selection, column visibility and cell helpers.
import { DataTable, DataTableColumnHeader } from "@plexui/vue/components/DataTable";For plain markup tables, use Table: Data Table draws its rows with its parts.
The examples import users (15 rows) and its User type from a local ./data file. Column definitions live in <script setup>: header and cell renderers are functions that return VNodes (h()), rendered with TanStack Table's FlexRender.
Examples
Overview
| Role | Department | Status | |
|---|---|---|---|
| Lindsay Walton | Front-end Developer | Engineering | Active |
| Courtney Henry | Designer | Design | Active |
| Tom Cook | Director of Product | Product | Active |
| Whitney Francis | Copywriter | Marketing | Inactive |
| Leonard Krasner | Senior Developer | Engineering | Active |
| Floyd Miles | UX Researcher | Design | Active |
Sorting
| Alicia Bell | Product Manager | Active |
| Anna Roberts | Backend Developer | Active |
| Benjamin Russel | DevOps Engineer | Active |
| Courtney Henry | Designer | Active |
| Emily Selman | VP Marketing | Active |
Pagination
| ID | Name | Department | Status |
|---|---|---|---|
| USR-001 | Lindsay Walton | Engineering | Active |
| USR-002 | Courtney Henry | Design | Active |
| USR-003 | Tom Cook | Product | Active |
| USR-004 | Whitney Francis | Marketing | Inactive |
| USR-005 | Leonard Krasner | Engineering | Active |
Row click
| Role | ||
|---|---|---|
| Lindsay Walton | lindsay@example.com | Front-end Developer |
| Courtney Henry | courtney@example.com | Designer |
| Tom Cook | tom@example.com | Director of Product |
| Whitney Francis | whitney@example.com | Copywriter |
Click a row to see selected user details.
Row selection
| Role | Status | ||
|---|---|---|---|
| Lindsay Walton | Front-end Developer | Active | |
| Courtney Henry | Designer | Active | |
| Tom Cook | Director of Product | Active | |
| Whitney Francis | Copywriter | Inactive | |
| Leonard Krasner | Senior Developer | Active |
0 of 15 rows selected
Cell variants
| ID | Name | Status | Joined | Salary |
|---|---|---|---|---|
| USR-001 | Lindsay Walton | Active | Jan 15, 2023, 09:00 AM | $95,000 |
| USR-002 | Courtney Henry | Active | Mar 22, 2023, 09:00 AM | $88,000 |
| USR-003 | Tom Cook | Active | Jun 10, 2022, 09:00 AM | $120,000 |
| USR-004 | Whitney Francis | Inactive | Jul 4, 2023, 09:00 AM | $72,000 |
| USR-005 | Leonard Krasner | Active | Feb 18, 2022, 09:00 AM | $115,000 |
| USR-006 | Floyd Miles | Active | May 11, 2023, 09:00 AM | $85,000 |
Filtering
| Role | Department | Status | |
|---|---|---|---|
| Lindsay Walton | Front-end Developer | Engineering | Active |
| Courtney Henry | Designer | Design | Active |
| Tom Cook | Director of Product | Product | Active |
| Whitney Francis | Copywriter | Marketing | Inactive |
| Leonard Krasner | Senior Developer | Engineering | Active |
Column visibility
| Role | Department | Status | Salary | |
|---|---|---|---|---|
| Lindsay Walton | Front-end Developer | Engineering | Active | $95,000 |
| Courtney Henry | Designer | Design | Active | $88,000 |
| Tom Cook | Director of Product | Product | Active | $120,000 |
| Whitney Francis | Copywriter | Marketing | Inactive | $72,000 |
| Leonard Krasner | Senior Developer | Engineering | Active | $115,000 |
API
DataTable
| Prop | Type | Default | Description |
|---|---|---|---|
columns | ColumnDef<TData>[] | — | Column definitions following TanStack Table v8 API; header and cell renderers return VNodes (required) |
data | TData[] | — | Data array to display (required) |
variant | "default" | "bordered" | "default" | Visual variant: bordered adds a rounded border and tinted header |
page-size | number | 10 | Rows per page. Set 0 or Infinity to disable pagination. The rows-per-page select offers 10, 20, 50, 100 and this size |
initial-sorting | SortingState | — | Initial column sorting state |
global-filter | string | — | Controlled search/filter string. Bind with v-model:global-filter |
column-visibility | VisibilityState | — | Controlled column visibility state. Bind with v-model:column-visibility |
enable-row-selection | boolean | false | Adds a first column (id select) with a checkbox per row and a header checkbox that selects every row on all pages, mixed when some are selected. A click on a checkbox is not a row click |
row-selection | RowSelectionState | — | Controlled row selection state. Bind with v-model:row-selection |
get-row-id | (row: TData) => string | — | Custom row ID accessor; selection keys use it |
empty-message | string | number | VNode | "No results." | Shown when no rows; the emptyMessage slot takes precedence |
show-pagination | boolean | true | Whether to show pagination controls. They hide on their own when every row fits on one page |
class | string | — | Class applied to outermost wrapper |
emptyMessage slot | VNode[] | — | Rich content shown when no rows |
@row-click | (row: TData) => void | — | Click handler for rows. Makes rows interactive: they take Tab and call it on Enter or Space |
@update:global-filter | (value: string) => void | — | Emitted with the next filter when the table changes it; powers v-model:global-filter |
@update:column-visibility | (visibility: VisibilityState) => void | — | Emitted with the next visibility; powers v-model:column-visibility |
@update:row-selection | (selection: RowSelectionState) => void | — | Emitted with the next selection; powers v-model:row-selection |
@row-click is a function prop rather than an event, because its presence makes the rows interactive; :on-row-click works the same. Column groups (a column definition with columns) render a header that spans its columns.
DataTableColumnHeader
| Prop | Type | Default | Description |
|---|---|---|---|
column | Column<TData, TValue> | — | TanStack Table column object (required) |
title | string | — | Display text for the header (required) |
class | string | — | Class applied to the header button (or text when the column cannot sort) |
Column helpers
| Prop | Type | Default | Description |
|---|---|---|---|
idCell(accessor) | CellComponent | — | Monospace ID with copy-on-click tooltip |
dateTimeCell(accessor, options?) | CellComponent | — | Formatted datetime with Intl.DateTimeFormat in the reader's time zone. It hydrates without a mismatch: the server writes the time in UTC (or in the timeZone of the options), and the reader's zone and wording follow once the page is in the browser. An ISO date or time written without a zone (2023-01-15, 2023-01-15T09:00) shows as written in every zone; a value that is no date shows as it is |
statusCell(accessor, colorMap?) | CellComponent | — | Badge cell with automatic status-to-color mapping |
tooltipHeader(label, description) | HeaderComponent | — | Header with dashed underline and info tooltip |
Each helper returns a functional component for a column's cell or header; TanStack Table's FlexRender renders it with the cell or header context.
Styling
Data Table draws its rows with the parts of Table, so it reads the tokens of Table › Styling.