WlDataTable

A table with optional virtualization, multi-column sorting, selection, and row details.
Components / Data v1.4.0

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>