WlDataTable
Behavior
Sort, select, resize columns, and expand details in a 10,000-row table.
1 | 8 Maple Avenue | 50 | ||
2 | 9 Maple Avenue | 187 | ||
3 | 10 Maple Avenue | 324 | ||
4 | 11 Maple Avenue | 461 | ||
5 | 12 Maple Avenue | 598 | ||
6 | 13 Maple Avenue | 735 | ||
7 | 14 Maple Avenue | 872 | ||
8 | 15 Maple Avenue | 1009 | ||
9 | 16 Maple Avenue | 1146 | ||
10 | 17 Maple Avenue | 1283 | ||
11 | 18 Maple Avenue | 170 | ||
Full example
<script setup lang="ts">
import type { WlDataTableColumn, WlDataTableSort, WlDataTableSortFn } from "legato-ui";
import { WlButton, WlCheckbox, WlDataTable } from "legato-ui";
import { computed, ref } from "vue";
const props = { preview: {} as Record<string, unknown> };
interface Order { id: number; total: number; address: string }
const rows = Array.from({ length: 10000 }, (_, index): Order => ({
id: index + 1,
total: 50 + ((index * 137) % 1250),
address: `${index + 8} Maple Avenue`
}));
const displayedRows = computed(() => props.preview?.virtual === false ? rows.slice(0, 24) : rows);
const columns = computed<readonly WlDataTableColumn<Order>[]>(() => [
{ key: "id", label: "Order", width: 132, sortable: true, pinned: "start" },
{ key: "address", label: "Address", width: 210, sortable: true },
{ key: "total", label: "Total", width: 130, sortable: true, numeric: true }
]);
const sort = ref<WlDataTableSort>(null);
const selection = ref<PropertyKey[]>([]);
const expanded = ref<PropertyKey[]>([]);
const widths = ref<Record<string, number>>({});
const showAddress = ref(true);
const hiddenColumns = computed(() => showAddress.value ? [] : ["address"]);
const table = ref<{ scrollToRow(index: number): void }>();
const sortRows: WlDataTableSortFn<Order> = (data, order) => {
const entries = "key" in order ? [order] : order;
return [...data].sort((left, right) => {
for (const { key, direction } of entries) {
const match = key === "id"
? left.id - right.id
: key === "total"
? left.total - right.total
: left.address.localeCompare(right.address);
if (match !== 0) return direction === "asc" ? match : -match;
}
return 0;
});
};
</script>
<template>
<WlDataTable
ref="table"
v-model:sort="sort"
v-model:expanded="expanded"
v-model:selection="selection"
v-model:column-widths="widths"
:hidden-columns="hiddenColumns"
:value="displayedRows"
:columns="columns"
:sort-fn="sortRows"
aria-label="Sort, select, resize columns, and expand details in a 10,000-row table."
:height="320"
row-key="id"
selection-mode="multiple"
virtual
sticky-header
multi-sort
resizable-columns
striped
>
<template #toolbar>
<div class="wl-inline" data-space="md">
<WlCheckbox v-model="showAddress">{{ "Show address" }}</WlCheckbox>
<WlButton size="sm" @click="table?.scrollToRow(displayedRows.length - 1)">{{ "Last record" }}</WlButton>
</div>
</template>
<template #selection-bar="{ selectedKeys, clear }">
<div class="wl-inline" data-space="md">
<span>{{ "Selected:" }} {{ selectedKeys.length }}</span>
<WlButton size="sm" @click="clear">{{ "Clear selection" }}</WlButton>
</div>
</template>
<template #expansion="{ row }">
<p>{{ "Address" }} · {{ row.address }}</p>
<p>{{ "Total" }} · {{ row.total }}</p>
</template>
</WlDataTable>
</template>Appearance
1 | 8 Maple Avenue | 50 | ||
2 | 9 Maple Avenue | 187 | ||
3 | 10 Maple Avenue | 324 | ||
4 | 11 Maple Avenue | 461 | ||
5 | 12 Maple Avenue | 598 | ||
6 | 13 Maple Avenue | 735 | ||
7 | 14 Maple Avenue | 872 | ||
8 | 15 Maple Avenue | 1009 | ||
9 | 16 Maple Avenue | 1146 | ||
10 | 17 Maple Avenue | 1283 | ||
11 | 18 Maple Avenue | 170 | ||
Full example
<script setup lang="ts">
import type { WlDataTableColumn, WlDataTableSort, WlDataTableSortFn } from "legato-ui";
import { WlButton, WlCheckbox, WlDataTable } from "legato-ui";
import { computed, ref } from "vue";
const props = { preview: {} as Record<string, unknown> };
interface Order { id: number; total: number; address: string }
const rows = Array.from({ length: 10000 }, (_, index): Order => ({
id: index + 1,
total: 50 + ((index * 137) % 1250),
address: `${index + 8} Maple Avenue`
}));
const displayedRows = computed(() => props.preview?.virtual === false ? rows.slice(0, 24) : rows);
const columns = computed<readonly WlDataTableColumn<Order>[]>(() => [
{ key: "id", label: "Order", width: 132, sortable: true, pinned: "start" },
{ key: "address", label: "Address", width: 210, sortable: true },
{ key: "total", label: "Total", width: 130, sortable: true, numeric: true }
]);
const sort = ref<WlDataTableSort>(null);
const selection = ref<PropertyKey[]>([]);
const expanded = ref<PropertyKey[]>([]);
const widths = ref<Record<string, number>>({});
const showAddress = ref(true);
const hiddenColumns = computed(() => showAddress.value ? [] : ["address"]);
const table = ref<{ scrollToRow(index: number): void }>();
const sortRows: WlDataTableSortFn<Order> = (data, order) => {
const entries = "key" in order ? [order] : order;
return [...data].sort((left, right) => {
for (const { key, direction } of entries) {
const match = key === "id"
? left.id - right.id
: key === "total"
? left.total - right.total
: left.address.localeCompare(right.address);
if (match !== 0) return direction === "asc" ? match : -match;
}
return 0;
});
};
</script>
<template>
<WlDataTable
ref="table"
v-model:sort="sort"
v-model:expanded="expanded"
v-model:selection="selection"
v-model:column-widths="widths"
:hidden-columns="hiddenColumns"
:value="displayedRows"
:columns="columns"
:sort-fn="sortRows"
aria-label="Sort, select, resize columns, and expand details in a 10,000-row table."
:height="320"
row-key="id"
selection-mode="multiple"
virtual
sticky-header
multi-sort
resizable-columns
striped
>
<template #toolbar>
<div class="wl-inline" data-space="md">
<WlCheckbox v-model="showAddress">{{ "Show address" }}</WlCheckbox>
<WlButton size="sm" @click="table?.scrollToRow(displayedRows.length - 1)">{{ "Last record" }}</WlButton>
</div>
</template>
<template #selection-bar="{ selectedKeys, clear }">
<div class="wl-inline" data-space="md">
<span>{{ "Selected:" }} {{ selectedKeys.length }}</span>
<WlButton size="sm" @click="clear">{{ "Clear selection" }}</WlButton>
</div>
</template>
<template #expansion="{ row }">
<p>{{ "Address" }} · {{ row.address }}</p>
<p>{{ "Total" }} · {{ row.total }}</p>
</template>
</WlDataTable>
</template>Selection
1 | 8 Maple Avenue | 50 | ||
2 | 9 Maple Avenue | 187 | ||
3 | 10 Maple Avenue | 324 | ||
4 | 11 Maple Avenue | 461 | ||
5 | 12 Maple Avenue | 598 | ||
6 | 13 Maple Avenue | 735 | ||
7 | 14 Maple Avenue | 872 | ||
8 | 15 Maple Avenue | 1009 | ||
9 | 16 Maple Avenue | 1146 | ||
10 | 17 Maple Avenue | 1283 | ||
11 | 18 Maple Avenue | 170 | ||
Full example
<script setup lang="ts">
import type { WlDataTableColumn, WlDataTableSort, WlDataTableSortFn } from "legato-ui";
import { WlButton, WlCheckbox, WlDataTable } from "legato-ui";
import { computed, ref } from "vue";
const props = { preview: {} as Record<string, unknown> };
interface Order { id: number; total: number; address: string }
const rows = Array.from({ length: 10000 }, (_, index): Order => ({
id: index + 1,
total: 50 + ((index * 137) % 1250),
address: `${index + 8} Maple Avenue`
}));
const displayedRows = computed(() => props.preview?.virtual === false ? rows.slice(0, 24) : rows);
const columns = computed<readonly WlDataTableColumn<Order>[]>(() => [
{ key: "id", label: "Order", width: 132, sortable: true, pinned: "start" },
{ key: "address", label: "Address", width: 210, sortable: true },
{ key: "total", label: "Total", width: 130, sortable: true, numeric: true }
]);
const sort = ref<WlDataTableSort>(null);
const selection = ref<PropertyKey[]>([]);
const expanded = ref<PropertyKey[]>([]);
const widths = ref<Record<string, number>>({});
const showAddress = ref(true);
const hiddenColumns = computed(() => showAddress.value ? [] : ["address"]);
const table = ref<{ scrollToRow(index: number): void }>();
const sortRows: WlDataTableSortFn<Order> = (data, order) => {
const entries = "key" in order ? [order] : order;
return [...data].sort((left, right) => {
for (const { key, direction } of entries) {
const match = key === "id"
? left.id - right.id
: key === "total"
? left.total - right.total
: left.address.localeCompare(right.address);
if (match !== 0) return direction === "asc" ? match : -match;
}
return 0;
});
};
</script>
<template>
<WlDataTable
ref="table"
v-model:sort="sort"
v-model:expanded="expanded"
v-model:selection="selection"
v-model:column-widths="widths"
:hidden-columns="hiddenColumns"
:value="displayedRows"
:columns="columns"
:sort-fn="sortRows"
aria-label="Sort, select, resize columns, and expand details in a 10,000-row table."
:height="320"
row-key="id"
selection-mode="multiple"
virtual
sticky-header
multi-sort
resizable-columns
striped
>
<template #toolbar>
<div class="wl-inline" data-space="md">
<WlCheckbox v-model="showAddress">{{ "Show address" }}</WlCheckbox>
<WlButton size="sm" @click="table?.scrollToRow(displayedRows.length - 1)">{{ "Last record" }}</WlButton>
</div>
</template>
<template #selection-bar="{ selectedKeys, clear }">
<div class="wl-inline" data-space="md">
<span>{{ "Selected:" }} {{ selectedKeys.length }}</span>
<WlButton size="sm" @click="clear">{{ "Clear selection" }}</WlButton>
</div>
</template>
<template #expansion="{ row }">
<p>{{ "Address" }} · {{ row.address }}</p>
<p>{{ "Total" }} · {{ row.total }}</p>
</template>
</WlDataTable>
</template>States
1 | 8 Maple Avenue | 50 | ||
2 | 9 Maple Avenue | 187 | ||
3 | 10 Maple Avenue | 324 | ||
4 | 11 Maple Avenue | 461 | ||
5 | 12 Maple Avenue | 598 | ||
6 | 13 Maple Avenue | 735 | ||
7 | 14 Maple Avenue | 872 | ||
8 | 15 Maple Avenue | 1009 | ||
9 | 16 Maple Avenue | 1146 | ||
10 | 17 Maple Avenue | 1283 | ||
11 | 18 Maple Avenue | 170 | ||
Full example
<script setup lang="ts">
import type { WlDataTableColumn, WlDataTableSort, WlDataTableSortFn } from "legato-ui";
import { WlButton, WlCheckbox, WlDataTable } from "legato-ui";
import { computed, ref } from "vue";
const props = { preview: {} as Record<string, unknown> };
interface Order { id: number; total: number; address: string }
const rows = Array.from({ length: 10000 }, (_, index): Order => ({
id: index + 1,
total: 50 + ((index * 137) % 1250),
address: `${index + 8} Maple Avenue`
}));
const displayedRows = computed(() => props.preview?.virtual === false ? rows.slice(0, 24) : rows);
const columns = computed<readonly WlDataTableColumn<Order>[]>(() => [
{ key: "id", label: "Order", width: 132, sortable: true, pinned: "start" },
{ key: "address", label: "Address", width: 210, sortable: true },
{ key: "total", label: "Total", width: 130, sortable: true, numeric: true }
]);
const sort = ref<WlDataTableSort>(null);
const selection = ref<PropertyKey[]>([]);
const expanded = ref<PropertyKey[]>([]);
const widths = ref<Record<string, number>>({});
const showAddress = ref(true);
const hiddenColumns = computed(() => showAddress.value ? [] : ["address"]);
const table = ref<{ scrollToRow(index: number): void }>();
const sortRows: WlDataTableSortFn<Order> = (data, order) => {
const entries = "key" in order ? [order] : order;
return [...data].sort((left, right) => {
for (const { key, direction } of entries) {
const match = key === "id"
? left.id - right.id
: key === "total"
? left.total - right.total
: left.address.localeCompare(right.address);
if (match !== 0) return direction === "asc" ? match : -match;
}
return 0;
});
};
</script>
<template>
<WlDataTable
ref="table"
v-model:sort="sort"
v-model:expanded="expanded"
v-model:selection="selection"
v-model:column-widths="widths"
:hidden-columns="hiddenColumns"
:value="displayedRows"
:columns="columns"
:sort-fn="sortRows"
aria-label="Sort, select, resize columns, and expand details in a 10,000-row table."
:height="320"
row-key="id"
selection-mode="multiple"
virtual
sticky-header
multi-sort
resizable-columns
striped
>
<template #toolbar>
<div class="wl-inline" data-space="md">
<WlCheckbox v-model="showAddress">{{ "Show address" }}</WlCheckbox>
<WlButton size="sm" @click="table?.scrollToRow(displayedRows.length - 1)">{{ "Last record" }}</WlButton>
</div>
</template>
<template #selection-bar="{ selectedKeys, clear }">
<div class="wl-inline" data-space="md">
<span>{{ "Selected:" }} {{ selectedKeys.length }}</span>
<WlButton size="sm" @click="clear">{{ "Clear selection" }}</WlButton>
</div>
</template>
<template #expansion="{ row }">
<p>{{ "Address" }} · {{ row.address }}</p>
<p>{{ "Total" }} · {{ row.total }}</p>
</template>
</WlDataTable>
</template>Props
Types, accepted values and literal defaults come from the public manifest. Inherited settings name their source; “Not set” means no default is declared.
v-model:sort: WlDataTableSortActive sort entries. An empty sort is represented by null.
| Prop | Type / values | Default | Purpose |
|---|---|---|---|
value * | readonly Row[] | Required | All rows available to this table. Fetching and paging belong to the application. |
columns * | readonly WlDataTableColumn< | Required | Typed field and virtual columns. |
rowKey | WlTableRowKey< | Not set | Field or callback returning the stable key of each row. |
selectionMode | WlTableSelectionMode | Not set | Selection behavior. The model stores row keys in both modes. |
multiSort | boolean | false | Keep multiple sort entries in priority order. |
resizableColumns | boolean | false | Let users resize columns using a pointer or keyboard. |
virtual | boolean | | false | Render fixed-height data rows and separate fixed-height detail rows. |
ariaLabel | string | Not set | Accessible name of the table. |
caption | string | Not set | Caption associated with the table. |
loading | boolean | Not set | Loading state supplied by the application. |
emptyMessage | string | Not set | Text shown when there are no rows. |
sortFn | WlDataTableSortFn< | Not set | Optional local sorting callback. Otherwise rows render in supplied order. |
height | string | | Not set | Scroll viewport height in pixels or as a CSS length. Virtual tables default to 360px. |
stickyHeader | boolean | Not set | Keep column headers at the top of the scroll area. Always on for virtual tables. |
density | WlDensity | Not set | Cell padding density. |
striped | boolean | Not set | Alternate the background of data rows. |
pt | WlPt< | Not set | Attributes of internal Legato UI elements. |
Events
| Event | Payload | When emitted |
|---|---|---|
rowClick | [detail: WlTableRowClick< | Pointer click on a row outside its interactive controls. |
update:sort | WlDataTableSort | The next sort entry, ordered list of sort entries, or null to clear sorting. |
update:selection | PropertyKey[] | The updated list of selected row keys. |
update:expanded | PropertyKey[] | The updated list of expanded row keys. |
update:hiddenColumns | string[] | The updated list of hidden column keys. |
update:columnWidths | Record< | Updated widths in pixels, keyed by column. |
Slots
| Slot | Type / values | Content |
|---|---|---|
empty | empty?: WlTableSlots< | Replacement content for a table with no rows. |
loading | loading?: WlTableSlots< | Replacement content while loading is active. |
expansion | expansion?: WlTableSlots< | Content of an expanded row. |
footer | footer?: WlTableSlots< | Footer content spanning all columns. |
caption | caption?: WlTableSlots< | Custom accessible table caption. |
toolbar | toolbar?: (props: {}) => unknown; | Filters and actions above the table. |
selection-bar | "selection-bar"?: (props: { selectedKeys: readonly PropertyKey[]; clear: () => void }) => unknown; | Bulk actions for the selected rows. |
cell-${string} | [name: `cell-${string}`]: ((props: WlTableCellSlotProps< | Content of a virtual column cell. Narrow unknown values for keys without a row field. |
header-${string} | [name: `header-${string}`]: ((props: WlDataTableHeaderSlotProps< | Custom column heading with the column and current sort state. |
cell-${Key} | { /** Cells for known row fields preserve the corresponding field value type. */ [Key in WlTableFieldKey< | Cells for known row fields preserve the corresponding field value type. |
header-${Key} | { /** Column headings for known row fields preserve their key domain. */ [Key in WlTableFieldKey< | Column headings for known row fields preserve their key domain. |
Pass-through: pt
Sections WlDataTable are listed below. Attributes merge in this order: createWlPt() WlConfig.ptpt instance. Class and style merge; the last supplied value takes priority for other attributes.
| Section | DOM | Purpose |
|---|---|---|
root | div.wl-data-table | Main element of the component. |
toolbar | div.wl-data-table__toolbar | Filters and actions above the table. |
selectionBar | div.wl-data-table__selection-bar | Actions for selected records. |
viewport | div.wl-data-table__viewport | Scrollable area. |
table | table.wl-data-table__table | The table section in WlConfig.pt.table configuration. |
caption | caption.wl-table__caption | Accessible caption naming the table. |
thead | thead.wl-table__head | The thead section in WlConfig.pt.table configuration. |
tbody | tbody.wl-table__body | The tbody section in WlConfig.pt.table configuration. |
bodyRow | tr.wl-table__row | The bodyRow section in WlConfig.pt.table configuration. |
bodyCell | td.wl-data-table__td | Data cell. |
cellContent | div.wl-data-table__cell-content | Main content area. |
selectionHeader | th.wl-table__selection | Header cell containing the select-all checkbox. |
selectionCell | td.wl-table__selection | Body cell containing a row-selection control. |
selectionInput | input | Native row checkbox/radio or header checkbox. |
headerCell | th.wl-data-table__th | Column header cell; sorting controls live inside it. |
sortButton | button.wl-table__sort | Column button that emits controlled sorting changes. |
resizeHandle | button.wl-data-table__resize | Column resize control. |
expansionHeader | th.wl-table__disclosure | Row details disclosure. |
expansionToggleCell | td.wl-table__disclosure | Row details disclosure. |
expansionToggle | button.wl-table__expand | Row details disclosure. |
expansionRow | tr.wl-table__expansion | Row details disclosure. |
expansionCell | td.wl-data-table__detail | Row details disclosure. |
expansionContent | div.wl-data-table__expansion-content | Scrollable area. |
emptyMessage | tr | The emptyMessage section in WlConfig.pt.table configuration. |
emptyMessageCell | td.wl-table__empty-cell | The emptyMessageCell section in WlConfig.pt.table configuration. |
mask | div.wl-table__mask | The mask section in WlConfig.pt.table configuration. |
loadingIcon | span.wl-table__loading | The loadingIcon section in WlConfig.pt.table configuration. |
footer | tfoot | Table footer. |
Sections refer to the component DOM. Dotted names identify a configuration group and its section; composite parts use their own pt groups. Global and local attributes merge, with class and style added together.
Keyboard and accessibility
- Use Tab to reach the sort and resize controls. Arrow keys resize a column by 8 pixels, Shift increases the step, and Home and End set the limits.
- In virtual mode, details occupy a separate fixed-height row with a focusable scroll area. Without virtual mode, details grow with their content.
- Use a caption or an accessible table name to identify the data before users enter the scroll area.
Keyboard and application responsibilities
Provide a meaningful accessible name and connect labels, hints and errors to the focusable element. Check the behavior with your own data and a screen reader.
WAI-ARIA Authoring PracticesChanges are emitted through v-model:sort. After selection, cancellation and reset, labels and states must remain clear.
In your application, check keyboard controls, zoom and focus visibility. State labels and required information must be readable in every theme.