Skip to content

Expandable rows ​

expandable adds a button to every row that opens a details area below it. Fill that area with the expand slot.

vue
<template>
  <VTable :columns="columns" :data="products" expandable rowKey="id" clientSide :itemsPerPage="5">
    <template #expand="{ row }">
      <strong>{{ row.name }}</strong> is in <em>{{ row.category }}</em>, {{ row.stock }} left in stock.
    </template>
  </VTable>
</template>

<script setup lang="ts">
import { VTable, type Column } from "v-table-system";
import { products } from "./data";

const columns: Column[] = [
  { key: "id", label: "ID" },
  { key: "name", label: "Name" },
  { key: "price", label: "Price" },
];
</script>

The slot receives row and index. Opening or closing a row emits expandChange with { row, expanded }, a good moment to load the details.

Set a rowKey so rows stay open when the data is loaded again.

Without a slot ​

The web component has no slots. Use expandRender there, a function that returns the HTML of the details area:

js
table.expandRender = (row) => `<strong>${row.name}</strong> has ${row.stock} left`;

WARNING

expandRender output is inserted as HTML. Escape anything that comes from users.

Released under the Apache-2.0 License.