DataTreeTable
Rows that expand into rows, with sorting that keeps the nesting and a filter that keeps the branches leading to matches.
WAI-ARIA tested
Import
import { TreeTable } from '@vitral/vue';
| 300 MB | Folder |
| 25 MB | Folder |
| 75 MB | Application |
| 75 KB | Folder |
| 1.2 GB | Folder |
Selection: none1<script setup lang="ts">2import { Column, TreeTable, type TreeNode } from '@vitral/vue';3import { ref } from 'vue';4 5const files: TreeNode[] = [6 {7 key: 'apps',8 data: { name: 'Applications', size: '300 MB', type: 'Folder' },9 children: [10 { key: 'vue', data: { name: 'Vue', size: '25 MB', type: 'Folder' }, children: [{ key: 'vue-app', data: { name: 'vue.app', size: '10 MB', type: 'Application' } }, { key: 'vue-cli', data: { name: 'cli', size: '15 MB', type: 'Application' } }] },11 { key: 'editor', data: { name: 'editor.app', size: '75 MB', type: 'Application' } }12 ]13 },14 {15 key: 'docs',16 data: { name: 'Documents', size: '75 KB', type: 'Folder' },17 children: [18 { key: 'work', data: { name: 'Work', size: '55 KB', type: 'Folder' }, children: [{ key: 'expenses', data: { name: 'Expenses.doc', size: '30 KB', type: 'Document' } }, { key: 'resume', data: { name: 'Resume.doc', size: '25 KB', type: 'Document' } }] },19 { key: 'invoices', data: { name: 'Invoices.txt', size: '20 KB', type: 'Text' } }20 ]21 },22 { key: 'music', data: { name: 'Música', size: '1.2 GB', type: 'Folder' }, children: [{ key: 'track', data: { name: 'Samba.mp3', size: '6 MB', type: 'Audio' } }] }23];24 25const expanded = ref<Record<string, boolean>>({ apps: true });26const selection = ref({});27</script>28 29<template>30 <TreeTable v-model:expanded-keys="expanded" v-model:selection-keys="selection" :value="files" selection-mode="checkbox" aria-label="Files">31 <Column field="name" header="Name" expander sortable />32 <Column field="size" header="Size" align="right" />33 <Column field="type" header="Type" sortable />34 </TreeTable>35 <small style="color: var(--vt-text-muted-color)">Selection: {{ Object.keys(selection).join(', ') || 'none' }}</small>36</template>
1<script setup lang="ts">2import { Column, InputText, TreeTable, type TreeNode } from '@vitral/vue';3import { ref } from 'vue';4 5const files: TreeNode[] = [6 {7 key: 'apps',8 data: { name: 'Applications', size: '300 MB', type: 'Folder' },9 children: [10 { key: 'vue', data: { name: 'Vue', size: '25 MB', type: 'Folder' }, children: [{ key: 'vue-app', data: { name: 'vue.app', size: '10 MB', type: 'Application' } }, { key: 'vue-cli', data: { name: 'cli', size: '15 MB', type: 'Application' } }] },11 { key: 'editor', data: { name: 'editor.app', size: '75 MB', type: 'Application' } }12 ]13 },14 {15 key: 'docs',16 data: { name: 'Documents', size: '75 KB', type: 'Folder' },17 children: [18 { key: 'work', data: { name: 'Work', size: '55 KB', type: 'Folder' }, children: [{ key: 'expenses', data: { name: 'Expenses.doc', size: '30 KB', type: 'Document' } }, { key: 'resume', data: { name: 'Resume.doc', size: '25 KB', type: 'Document' } }] },19 { key: 'invoices', data: { name: 'Invoices.txt', size: '20 KB', type: 'Text' } }20 ]21 },22 { key: 'music', data: { name: 'Música', size: '1.2 GB', type: 'Folder' }, children: [{ key: 'track', data: { name: 'Samba.mp3', size: '6 MB', type: 'Audio' } }] }23];24 25const query = ref('');26</script>27 28<template>29 <InputText v-model="query" placeholder="Filter by name" aria-label="Filter by name" style="align-self: flex-start" />30 <TreeTable :value="files" :global-filter="query" :global-filter-fields="['name']" paginator :rows="2" striped-rows show-gridlines selection-mode="single" aria-label="Files, filtered">31 <Column field="name" header="Name" expander />32 <Column field="type" header="Type" />33 </TreeTable>34</template>
API
Read from packages/vue/src/components/TreeTable/types.ts, so it says what the component actually accepts.
Props
Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.
Emits
Slots
- ChartSVG charts with no dependency, over twenty types from one options object, with tooltips, legends, zoom and synced groups, readable from the keyboard.
- DataGridA data table that sorts, filters, pages and selects, locally or on your server, with columns the reader can resize, reorder, pin and hide.
- DataTableThe small table: rows already in hand, sorted, striped and sized, with a sticky head. DataGrid takes over when it needs more.
- DataViewSorting and paging over your own template per item, shown as a list or a grid.