Skip to main content

Treeview

info

For more details about Vuetify’s usage of Treeview component, click Treeview page.
For more prop explanations, click Vuetify Treeview API page.

Props

AttributeDescriptionTypeDefault
valueAllows one to control which nodes are selected. The array consists of the item-key of each selected item.array[]
itemsAn array of items used to build the treeviewarray[]
activatableAllows user to mark a node as active by clicking on itbooleanfalse
classProp that determines the class to add to the Treeviewstringundefined
colorApplies specified colorstringundefined
denseHide opposite slot content, and position all items to one side of timeline.booleanfalse
hovertableApplies a hover class when mousing over nodesbooleanfalse
itemDisabledSet property of items’s disabled valuestring - array - functiondisabled
loadingIconIcon used when node is in a loading statestring'$loading'
onIconIcon used when leaf node is selected or when a branch node is fully selected. Only visible when selectable is true.string'$checkboxOn'
openAllWhen true will cause all branch nodes to be opened when component is mountedbooleanfalse
openOnClickWhen true will cause nodes to be opened by clicking anywhere on it, instead of only opening by clicking on expand icon. When using this prop with activatable you will be unable to mark nodes with children as active.booleanfalse
selectableWill render a checkbox next to each node allowing them to be selectedbooleanfalse
selectedColorThe color of the selection checkboxstring'accent'
selectionTypeControls how the treeview selects nodes. There are two modes available: ‘leaf’ and ‘independent’string'leaf'
activeSyncable prop that allows one to control which nodes are active. The array consists of the item-key of each active itemarray[]
denseDecreases the height of the itemsbooleanfalse
expandIconIcon used to indicate that a node can be expandedstring'$subgroup'
itemChildrenProperty on supplied items that contains its childrenstring'children'
itemKeyProperty on supplied items used to keep track of node state. The value of this property has to be unique among all itemsstring'id'
itemTextProperty on supplied items that contains its label textstring'name'
multipleActiveWhen true, allows user to have multiple active nodes at the same timebooleanfalse
offIconIcon used when node is not selected. Only visible when selectable is truestring'$checkboxOff'
openSyncable prop that allows one to control which nodes are open. The array consists of the item-key of each open itemarray[]
openOnClickWhen true will cause nodes to be opened by clicking anywhere on it, instead of only opening by clicking on expand iconbooleanfalse
searchThe search model for filtering resultsstringundefined
shapedProvides an alternative active style for Treeview node. Only visible when activatable is truebooleanfalse
tabindexAllows component to give and receive focus.numberundefined
transitionApplies a transition when nodes are opened and closedbooleanfalse
visibleVisibility of Treeview componentbooleantrue

Events

AttributeDescription
input(array)Emits the array of selected items when this value changes
update:active(array)Emits the array of active items when this value changes
update:open(array)Emits the array of open items when this value changes

Slots

AttributeDescription
appendAppends content after label.{ item: any, leaf: boolean, selected: boolean, indeterminate: boolean, active: boolean, open: boolean }
labelLabel content.{ item: any, leaf: boolean, selected: boolean, indeterminate: boolean, active: boolean, open: boolean }
prependPrepends content before label.{ item: any, leaf: boolean, selected: boolean, indeterminate: boolean, active: boolean, open: boolean }

image

image

image

image

Component Samples

Treeview Performance with Server-Side Search and Expandable Nodes

info

In the Treeview component, only a small initial dataset is rendered and the full data is stored in the store, with search and filter operations performed on it. This approach must be used for large datasets, otherwise performance can degrade significantly.

When performing searches on a Treeview component with a large dataset, loading all data directly into the Treeview can cause performance issues. Therefore, only a small initial dataset is displayed, while the full dataset is stored. When the user searches, filtering is performed with a debounce, and matching nodes are set to the Treeview. Parent nodes are expanded only if their children match. These practices keep searches fast and efficient. It can be applied to the component by following the steps below;

  • When the page first loads, the Treeview is provided with only a small dataset (initialData) for fast rendering. The full dataset (fullData) is set in the store*, and searching and filtering are performed using this data.

EndRender

// The full tree data and the initial subset are set in the store
quick.store.set("treeFullData", fullData);
quick.store.set("treeInitialData", initialData);
// The Treeview component's items are set to the initial subset
components.myTreeview.items = initialData;
  • When the user types into the TextField, the filtering process runs with a 300ms debounce.

    • If the input value has 3 or more characters, the entire dataset (treeFullData) is filtered.

    • Matching nodes are set to the Treeview, and if there are matching children, parent nodes are automatically expanded (openIds).

    • If no matches are found, or the input is less than 3 characters, the Treeview displays the initial data (initialData).

      Input(value)

      function onInput(value, caseSensitive) {
      const comp = components.myTreeview as any;
      const searchValueRaw = (value || "").trim();
      clearTimeout(comp._debounceTimeout);
      comp._debounceTimeout = setTimeout(() => {
      const allData = quick.store.get("treeFullData") || [];
      const initial = quick.store.get("treeInitialData") || [];
      if (searchValueRaw.length >= 5) {
      const openIds = [];
      const filtered = filterTreeWithOpenIds(allData, searchValueRaw, caseSensitive, openIds);
      if (filtered.length > 0) {
      comp.items = filtered;
      comp.open = openIds;
      } else {
      comp.items = caseSensitive ? initial : [];
      comp.open = [];
      comp.search = "";
      }
      } else {
      comp.items = initial;
      comp.open = [];
      comp.search = "";
      }
      }, 300);
      }
efficientTreeviewSearchforLargeDatasets

Samples Qjson

treeview
treeview2
TreeViewExample