AdaptTable for Vue Unstyled

Nested tables in Vue Unstyled

Open a row and the panel holds another Vue Unstyled table — the same component, not a hand-built list. Each person has recent orders; the inner table has its own columns and row keys.

nestedTable() mounts the kit's DataTable with defaults that keep the two tables from fighting over the URL. Rows with no nested table can still use rowDetail().

The expand chevron and both tables are Vue Unstyled.

The code

<script setup lang="ts">
import { h } from "vue";
import type { ColumnDef } from "@adapttable/vue";
import { DataTable } from "@adapttable/vue-unstyled";
import { nestedTable } from "@adapttable/vue-unstyled/nested-table";

interface Order {
  id: string;
  item: string;
}

interface Customer {
  id: string;
  name: string;
  orders: Order[];
}

defineProps<{ rows: readonly Customer[] }>();

const columns: ColumnDef<Customer>[] = [{ key: "name" }];
const orderColumns: ColumnDef<Order>[] = [{ key: "item" }];
const rowKey = (row: Customer) => row.id;
const features = [
  nestedTable<Customer>((row) => ({
    label: `Orders for ${row.name}`,
    table: (defaults) =>
      h(DataTable<Order>, {
        ...defaults,
        data: row.orders,
        columns: orderColumns,
        rowKey: (order: Order) => order.id,
      }),
  })),
];
</script>

<template>
  <DataTable
    :data="rows"
    :columns="columns"
    :row-key="rowKey"
    :features="features"
  />
</template>

Install

pnpm add @adapttable/vue-unstyled @adapttable/vue @adapttable/core

The same feature in the other kits

More Vue Unstyled features

Reference: tree-data, row-expansion. More of this kit: AdaptTable for Vue Unstyled, or the live demo.