Tree
Quasar Tree represents a highly configurable component that displays hierarchical data, such as a table of contents in a tree structure.
Installation
Edit /quasar.conf.js
:
framework: { |
Basic Usage
This is the simplest Tree that you can write:
<template> |
Notice that nodes must have a unique key defined by a property of each key. In the example above, labels are unique so we’re using label
prop to define these keys. However, you can add any property to the nodes (like ‘id’ or anything you want) and then use that property (like node-key="id"
).
Vue Properties
Vue Property | Type | Description |
---|---|---|
nodes | Array | Vue model for the Tree |
node-key | String | Property of node to use as unique key. |
label-key | String | (v0.17.11+) Property of node to use as label. |
color | String | Color of the connector lines. |
control-color | String | Color of checkboxes. |
text-color | String | Color of text. |
dark | Boolean | When rendering on a dark background. |
icon | String | Connector icon for each node. |
selected | Any | Use .sync. The unique key value of the selected node. |
tick-strategy | String | One of ‘leaf’, ‘leaf-filtered’, ‘strict’, ‘none’. |
ticked | Array | Use .sync. Node unique keys of ticked nodes. |
expanded | Array | Use .sync. Node unique keys of expanded nodes. |
default-expand-all | Boolean | Expan all nodes on first render. |
accordion | Boolean | Expanding a node closes its siblings. |
filter | String | String to be used when filtering nodes. |
filter-method | Function | Custom filtering method. |
no-nodes-label | String | Override default i18n of message when no nodes are available. |
no-results-label | String | Override default i18n of message when no nodes are available after filtering. |
duration | Number | (v0.17.13+) Toggle animation duration in milliseconds. Default: 300 |
Nodes model structure
The following describes a node’s properties that are taken into account by QTree’s v-model.
Node Property | Type | Description |
---|---|---|
label | String | Node’s label |
icon | String | Node’s icon |
iconColor | String | (v0.17.9+) Node’s icon color. One from Quasar Color Palette. |
img | String | Node’s image. Use statics folder. Example: ‘statics/mountains.png’ |
avatar | String | Node’s avatar. Use statics folder. Example: ‘statics/boy-avatar.png’ |
children | Array | Array of nodes as children. |
disabled | Boolean | Is node disabled? |
expandable | Boolean | Is node expandable? |
tickable | Boolean | When using a tick strategy, each node shows a checkbox. Should a node’s checkbox be disabled? |
noTick | Boolean | When using a tick strategy, should node display a checkbox? |
tickStrategy | String | Override global tick strategy for this node only. One of ‘leaf’, ‘leaf-filtered’, ‘strict’, ‘none’. |
lazy | Boolean | Should children be lazy loaded? In this case also don’t specify ‘children’ prop. |
header | String | Node header scoped slot name, without the required ‘header-‘ prefix. Example: ‘story’ refers to ‘header-story’ scoped slot. |
body | String | Node body scoped slot name, without the required ‘body-‘ prefix. Example: ‘story’ refers to ‘body-story’ scoped slot. |
Selection vs Ticking, Expansion
- Selection (through QTree
selected
prop) refers to the currently selected node (gets highlighted with different background). - Ticking (through QTree
ticked
prop) refers to the checkbox associated with each node. - Expansion (through QTree
expanded
prop) refers to the nodes that are expanded.
All properties above require the .sync
modifier in order for them to work correctly. Example:
<!-- DO NOT forget about adding ".sync" --> |
Tick Strategy
There are three ticking strategy: ‘leaf’, ‘leaf-filtered’, ‘strict’ with an additional (and default) ‘none’ which disables ticking.
Strategy | Description |
---|---|
leaf | Ticked nodes are only the leaves. Ticking a node influences the parent’s ticked state too (parent becomes partially ticked or ticked), as well as its children (all tickable children become ticked). |
leaf-filtered | Same concept as leaf , only that this strategy applies only to filtered nodes (the nodes that remain visible after filtering). |
strict | Ticked nodes are independent of parent or children tick state. |
You can apply a global tick strategy for a QTree and locally change the ticking strategy for a certain node by specifying the tickStrategy
in the nodes
model.
Custom Filter Method
You can customize the filtering method by specifying the filter-method
prop. The method below is actually the default filtering strategy:
<template> |
Vue Methods
Vue Property | Description |
---|---|
getNodeByKey(key) | Get a node by specifying its unique key. |
collapseAll() | Collapses all nodes. Useful if not using a synched expanded bind, otherwise just set expanded to an empty array. |
expandAll() | Expands all nodes. Useful if not using a synched expanded bind. |
isTicked(key) | Returns a boolean specifying if node with key is ticked. |
isExpanded(key) | Returns a boolean specifying if node with key is expanded. |
getTickedNodes() | Returns an array with keys of nodes that are ticked. Useful if not using a synched ticked bind. |
getExpandedNodes() | Returns an array with keys of nodes that are expanded. Useful if not using a synched expanded bind. |
Examples
Node icon/avatar/image, controlling expansion and colored
<template> |
Customizing nodes (header and body slots)
<template> |
Applying a default header and body slot
<template> |
Filtering nodes
<template> |
Accordion mode (sibling nodes get contracted when one gets expanded)
<q-tree |
Selectable nodes
<template> |
Tickable nodes & strategies
<template> |
Lazy loading nodes
<template> |