WlTable
Change props to see the result: the example and code use the same settings. “Reset” restores the initial values.
Settings
Empty-state text; falls back to WlConfig.locale.noData (No data in English).
Visible table caption associated with the table.
Accessible name when an external label is not referenced.
Loading state.
Keep table column headers visible within a scrolling container.
Choose a dataset or edit the array in the SFC below.
Props value, columns, pt, rowKey, rowClass, sortFn, selectionMode, models, handlers and slots can be edited in the SFC. See their descriptions in API.
Example
| Team guide | Done | |
| Research plan | In progress |
Explore the live example and copy its Vue SFC into your application. Settings on the left can be combined.
Code for your application
Vue SFC · current settings
<script setup lang="ts">
import { computed, ref } from "vue";
import { WlPill, WlTable, type WlTableSort, type WlTableSortFn } from "legato-ui";
interface MaterialRow { id: number; name: string; status: string }
const rows = computed<MaterialRow[]>(() => [
{ id: 1, name: "Team guide", status: "Done" },
{ id: 2, name: "Research plan", status: "In progress" }
]);
const sort = ref<WlTableSort | null>(null);
const selection = ref<PropertyKey[]>([]);
const sortRows: WlTableSortFn<MaterialRow> = (value, order) => [...value].sort((left, right) => {
const result = (order.key === "name" ? left.name : left.status).localeCompare(order.key === "name" ? right.name : right.status);
return order.direction === "asc" ? result : -result;
});
</script>
<template>
<div class="wl-stack" data-space="md">
<WlTable
v-model:sort="sort"
v-model:selection="selection"
:columns="[
{ key: 'name', label: 'Material', sortable: true },
{ key: 'status', label: 'Status', sortable: true }
]"
:value="rows"
row-key="id"
selection-mode="multiple"
caption="Team materials"
:sort-fn="sortRows"
:pt="{ root: { style: { overflowX: 'auto' } } }"
><template #cell-status="{ value }"><WlPill tone="info" :label="String(value)" /></template></WlTable>
</div>
</template>Cells, empty state and loading
Columns, numeric, cell-title/cell-status, empty slot, loading, accessible scrolling and a custom table in default.
| Status | |||
|---|---|---|---|
| Done | 8 | ||
| In progress | 3 |
Click a material title. Hours use numeric alignment.
Selected: 0
| Section | Records |
|---|---|
| Documents | 2 |
Vue SFC · additional example
<script setup lang="ts">
import { WlButton, WlPill, WlTable, type WlTableColumn, type WlTableSort, type WlTableSortFn } from "legato-ui";
import { computed, ref } from "vue";
interface MaterialRow { id: number; title: string; status: string; hours: number }
const state = ref<"ready" | "empty" | "loading">("ready");
const selected = ref("");
const selection = ref<PropertyKey[]>([]);
const sort = ref<WlTableSort | null>(null);
const columns = computed<readonly WlTableColumn<MaterialRow>[]>(() => [
{ key: "title", label: "Material", sortable: true },
{ key: "status", label: "Status", align: "center" },
{ key: "hours", label: "Hours", numeric: true, align: "end", sortable: true }
]);
const rows = computed<readonly MaterialRow[]>(() => [
{ id: 1, title: "Release plan", status: "done", hours: 8 },
{ id: 2, title: "Overview", status: "progress", hours: 3 }
]);
const sortRows: WlTableSortFn<MaterialRow> = (value, order) => [...value].sort((left, right) => {
const result = order.key === "hours" ? left.hours - right.hours : left.title.localeCompare(right.title);
return order.direction === "asc" ? result : -result;
});
</script>
<template>
<div class="wl-stack" data-space="lg" data-table-example="WlTable">
<div
class="wl-inline"
data-space="sm"
role="group"
aria-label="Table state"
><WlButton
v-for="item in (['ready', 'empty', 'loading'] as const)"
:key="item"
size="sm"
:aria-pressed="state === item"
@click="state = item"
>{{ { ready: "Data", empty: "Empty", loading: "Loading" }[item] }}</WlButton></div>
<div
class="showcase-table-scroll"
tabindex="0"
role="region"
aria-label="Materials table — horizontal scrolling"
>
<WlTable
v-model:sort="sort"
v-model:selection="selection"
:value="state === 'empty' ? [] : rows"
:columns="columns"
:loading="state === 'loading'"
row-key="id"
selection-mode="multiple"
sticky-header
caption="Team materials"
:sort-fn="sortRows"
:row-class="row => ({ 'showcase-table-done': row.status === 'done' })"
>
<template #header-hours="{ column }">{{ column.label }}</template>
<template #cell-title="{ value }"><WlButton
size="sm"
variant="link"
:disabled="state === 'loading'"
@click="selected = String(value)"
>{{ value }}</WlButton></template>
<template #cell-status="{ value }">
<WlPill
:tone="value === 'done' ? 'success' : 'info'"
:label="value === 'done' ? 'Done' : 'In progress'"
/>
</template>
<template #empty>
<div class="wl-stack" data-space="sm">
<span>{{ "No materials yet." }}</span>
<div><WlButton size="sm" @click="state = 'ready'">{{ "Restore list" }}</WlButton></div>
</div>
</template>
<template #loading>
<div class="wl-stack" data-space="sm">
<span role="status">{{ "Loading materials…" }}</span>
<WlButton size="sm" @click="state = 'ready'">{{ "Cancel" }}</WlButton>
</div>
</template>
</WlTable>
</div>
<p class="wl-text-small" role="status">
{{ selected
? "Selected material: " + selected
: "Click a material title. Hours use numeric alignment." }}
</p>
<p class="wl-text-small">{{ "Selected:" }} {{ selection.length }}</p>
<WlTable>
<table class="showcase-custom-table">
<caption>{{ "Default slot: custom table" }}</caption>
<thead>
<tr>
<th scope="col">{{ "Section" }}</th>
<th scope="col">{{ "Records" }}</th>
</tr>
</thead>
<tbody><tr><th scope="row">{{ "Documents" }}</th><td>2</td></tr></tbody>
</table>
</WlTable>
</div>
</template>
<style scoped>
.showcase-table-scroll { max-width: 100%; overflow-x: auto; border: 1px solid var(--wl-border); border-radius: var(--wl-corner-control); }
.showcase-table-scroll :deep(table) { min-width: 360px; }
.showcase-table-scroll:focus-visible { outline: 2px solid var(--wl-focus-color); outline-offset: 2px; }
.showcase-table-scroll :deep(.showcase-table-done) { font-weight: 600; }
.showcase-custom-table { width: 100%; border-collapse: collapse; text-align: left; }
.showcase-custom-table th, .showcase-custom-table td { padding: var(--wl-space-sm); border-bottom: 1px solid var(--wl-border); }
.showcase-custom-table caption { text-align: left; padding-bottom: var(--wl-space-sm); }
</style>