Tree
# FxTree Tree
Display hierarchical data in a clear structure that can be expanded or collapsed.
# Attributes
| Attribute | Description | Type | Optional | Default |
|---|---|---|---|---|
| data | Tree data | array | — | — |
| empty-text | Text displayed when there is no data | String | — | — |
| node-key | Unique identity key name for nodes, its value should be unique across the whole tree | String | — | — |
| props | Configuration options, see table below | object | — | — |
| render-after-expand | Whether to render child nodes only after a parent node is expanded for the first time | boolean | — | true |
| load | Method for loading subtree data, only works when lazy is true | function(node, resolve) | — | — |
| render-content | Render function for tree node content | Function(h, { node, data, store }) | — | — |
| highlight-current | Whether current node is highlighted | boolean | — | false |
| default-expand-all | Whether to expand all nodes by default | boolean | — | false |
| expand-on-click-node | Whether expanding and collapsing node is triggered by clicking node, the default value is true. If it's false, only clicking the arrow icon triggers expanding and collapsing | boolean | — | true |
| check-on-click-node | Whether checking node is triggered by clicking node, the default value is false, that is, only clicking the checkbox triggers checking node | boolean | — | false |
| auto-expand-parent | Whether to expand parent node when expanding a child node | boolean | — | true |
| default-expanded-keys | Array of keys of initially expanded nodes | array | — | — |
| show-checkbox | Whether node is selectable | boolean | — | false |
| check-strictly | Whether checked state of a node not affects its parent and child nodes when show-checkbox is true | boolean | — | false |
| default-checked-keys | Array of keys of initially checked nodes | array | — | — |
| current-node-key | Key of currently selected node, must be set only if node-key is set | string, number | — | — |
| filter-node-method | Method that will be executed on each node when filtering. If false is returned, the node will be hidden | Function(value, data, node) | — | — |
| accordion | Whether only one node among the same level can be expanded at one time | boolean | — | false |
| indent | Horizontal indentation of nodes in adjacent levels in pixels | number | — | 16 |
| icon-class | Custom tree node icon | string | — | — |
| lazy | Whether to lazy load leaf node, used with load attribute | boolean | — | false |
| draggable | Whether enable tree node drag and drop | boolean | — | false |
| allow-drag | Function that determines if a node can be dragged | Function(node) | — | — |
| allow-drop | Function that determines if a node can be dropped. The type parameter has three possible values: 'prev' (inserting before the target node), 'inner' (inserting at the bottom of the target node) and 'next' (inserting after the target node) | Function(draggingNode, dropNode, type) | — | — |
# props
| Attribute | Description | Type | Optional | Default |
|---|---|---|---|---|
| label | Specify which property of the node object is used as the node's label | string, function(data, node) | — | — |
| children | Specify which property of the node object is used as the node's subtree | string | — | — |
| disabled | Specify which property of the node object is used as the node's disabled | boolean, function(data, node) | — | — |
| isLeaf | Specify whether the node is a leaf node, works only when lazy is true | boolean, function(data, node) | — | — |
# Methods
Tree internally uses Node objects to wrap the data passed by users, which is used to save the current state of nodes.
Tree has the following methods:
| Method | Description | Parameters |
|---|---|---|
| filter | Filter all tree nodes, filtered nodes will be hidden | Accept one parameter of any type, which will be passed to filter-node-method as its first parameter |
| updateKeyChildren | Set child nodes by keys, node-key is required | (key, data) Accept two parameters: 1. key of the node 2. array of node data |
| getCheckedNodes | If node is selectable (show-checkbox is true), it returns the currently checked array of nodes | (leafOnly, includeHalfChecked) Accept two boolean type parameters: 1. whether to return only leaf nodes, default false 2. whether to include half-checked nodes, default false |
| setCheckedNodes | Set checked nodes, node-key is required | (nodes) Accept an array of checked node data |
| getCheckedKeys | If node is selectable (show-checkbox is true), it returns the currently checked array of node keys | (leafOnly) Accept a boolean type parameter. If true, it only returns the keys of checked leaf nodes, default false |
| setCheckedKeys | Set checked nodes by keys, node-key is required | (keys, leafOnly) Accept two parameters: 1. array of keys of checked nodes 2. boolean type, if true only set leaf nodes' checked state, default false |
| setChecked | Set checked state of a node by key/data, node-key is required | (key/data, checked, deep) Accept three parameters: 1. key or data of the node 2. boolean, whether the node is checked 3. boolean, whether to set child nodes, default false |
| getHalfCheckedNodes | If node is selectable (show-checkbox is true), it returns the currently half-checked array of nodes | — |
| getHalfCheckedKeys | If node is selectable (show-checkbox is true), it returns the currently half-checked array of node keys | — |
| getCurrentKey | Get the key of currently selected node, return null if no node is selected, node-key is required | — |
| getCurrentNode | Get the data of currently selected node, return null if no node is selected | — |
| setCurrentKey | Set the currently selected node by key, node-key is required. If key is null, remove current highlight | (key) Key of the node to be selected, if null then remove current highlighted node |
| setCurrentNode | Set the currently selected node by node object, node-key is required | (node) The node object to be selected |
| getNode | Get the node in the tree component by data or key | (data) The key or data of the node to get |
| remove | Remove a node from the tree, node-key is required | (data) The data or node object of the node to be removed |
| append | Append a child node to a node in the tree | (data, parentNode) Accept two parameters: 1. data of the child node to be appended 2. data, key or node of the parent node |
| insertBefore | Insert a node before a node in the tree | (data, refNode) Accept two parameters: 1. data of the node to be inserted 2. data, key or node of the reference node |
| insertAfter | Insert a node after a node in the tree | (data, refNode) Accept two parameters: 1. data of the node to be inserted 2. data, key or node of the reference node |
# Events
| Event Name | Description | Callback Parameters |
|---|---|---|
| node-click | Callback when node is clicked | Three parameters: the node object corresponding to the node in the array passed to the data attribute, node's Node object, node component itself |
| node-contextmenu | Triggered when a node is right-clicked | Four parameters: event, the node object corresponding to the node in the array passed to the data attribute, node's Node object, node component itself |
| check-change | Callback when the checked state of the node changes | Three parameters: the node object corresponding to the node in the array passed to the data attribute, whether the node itself is checked, whether the node's subtree has checked nodes |
| check | Triggered when the checkbox is clicked | Two parameters: the node object corresponding to the node in the array passed to the data attribute, the current checked state object of the tree, containing four properties: checkedNodes, checkedKeys, halfCheckedNodes, halfCheckedKeys |
| current-change | Callback when current node changes | Two parameters: the current node's data, the current node's Node object |
| node-expand | Triggered when node is expanded | Three parameters: the node object corresponding to the node in the array passed to the data attribute, node's Node object, node component itself |
| node-collapse | Triggered when node is collapsed | Three parameters: the node object corresponding to the node in the array passed to the data attribute, node's Node object, node component itself |
| node-drag-start | Triggered when drag starts | Two parameters: the dragged node's Node object, event |
| node-drag-enter | Triggered when dragging enters other nodes | Three parameters: the dragged node's Node object, the entered node's Node object, event |
| node-drag-leave | Triggered when dragging leaves a node | Three parameters: the dragged node's Node object, the left node's Node object, event |
| node-drag-over | Triggered when dragging over a node (like mouseover) | Three parameters: the dragged node's Node object, the currently entered node's Node object, event |
| node-drag-end | Triggered when drag ends (may or may not succeed) | Four parameters: the dragged node's Node object, the last entered node when drag ends (may be null), the drop position of the dragged node (before, after, inner), event |
| node-drop | Triggered when drag ends successfully | Four parameters: the dragged node's Node object, the last entered node, the drop position of the dragged node (before, after, inner), event |
# Scoped Slot
| name | Description |
|---|---|
| — | Custom content for tree nodes, parameter is { node, data } |
# Basic Usage
Basic tree structure display.
Copy
# Checkbox
For scenarios where you need to select tree nodes.
Copy
# Custom Leaf Node in Lazy Mode
Copy
# Default Expanded and Default Checked
Set certain tree nodes to be expanded or checked by default.
Copy
# Disabled
Set certain tree nodes to be disabled.
Copy
# Tree Node Selection
Copy
# Custom Node Content
The content of tree nodes can be customized, you can add buttons or icons to nodes.
Using render-content
Using scoped slot
Copy
# Filtering
Filter tree nodes through keywords.
Copy
# Accordion
Only one node among the same level can be expanded at one time.
Copy
# Draggable
Enable tree node drag and drop via draggable attribute.
Copy