AdaptTable for shadcn-vue

Tree data in shadcn-vue

A tree grid is a different shape from a grouped table: the rows themselves nest, rather than being collected under synthetic headers. Compose tree() with getChildren or getParentId and it renders the hierarchy.

Children indent under their parent and a shadcn-vue chevron control in the tree column opens and closes each branch. Give hasChildren and onLoadChildren and a branch fetches its children as it opens, showing that it is loading; a failed fetch closes it again, so the next click retries.

On a phone each card leads with the same chevron and indents by depth. Sorting reorders each branch in place, and a search shows the rows it matches.

The code

<script setup lang="ts">
import type { ColumnDef } from "@adapttable/vue";
import { DataTable } from "@adapttable/shadcn-vue";
import { tree } from "@adapttable/shadcn-vue/tree";

interface Employee {
  id: string;
  name: string;
  team: string;
  managerId?: string;
}

defineProps<{ people: readonly Employee[] }>();

const columns: ColumnDef<Employee>[] = [{ key: "name" }, { key: "team" }];
const rowKey = (row: Employee) => row.id;
const features = [
  tree<Employee>({ getParentId: (row) => row.managerId, treeColumn: "name" }),
];
</script>

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

Install

pnpm add @adapttable/shadcn-vue @adapttable/vue @adapttable/core reka-ui

The same feature in the other kits

More shadcn-vue features

Reference: tree-data. More of this kit: AdaptTable for shadcn-vue, or the live demo.