AdaptTable for Element Plus

Nested tables in Element Plus

Open a row and the panel holds another Element Plus 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 Element Plus.

The code

<script setup lang="ts">
import { h } from "vue";
import type { ColumnDef } from "@adapttable/vue";
import { DataTable } from "@adapttable/element-plus";
import { nestedTable } from "@adapttable/element-plus/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/element-plus @adapttable/vue @adapttable/core element-plus

The same feature in the other kits

More Element Plus features

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