|
| 1 | +# <ElBadge value="beta">Tree V2 virtualized tree</ElBadge> |
| 2 | + |
| 3 | +Tree view with blazing fast scrolling performance for any amount of data |
| 4 | + |
| 5 | +## Basic usage |
| 6 | + |
| 7 | +Basic tree structure. |
| 8 | + |
| 9 | +:::demo |
| 10 | + |
| 11 | +tree-v2/basic |
| 12 | + |
| 13 | +::: |
| 14 | + |
| 15 | +## Selectable |
| 16 | + |
| 17 | +Used for node selection. |
| 18 | + |
| 19 | +:::demo |
| 20 | + |
| 21 | +tree-v2/selectable |
| 22 | + |
| 23 | +::: |
| 24 | + |
| 25 | +## Disabled checkbox |
| 26 | + |
| 27 | +The checkbox of a node can be set as disabled. |
| 28 | + |
| 29 | +:::demo In the example, `disabled` property is declared in defaultProps, and some nodes are set as `disabled: true`. The corresponding checkboxes are disabled and can't be clicked. |
| 30 | + |
| 31 | +tree-v2/disabled |
| 32 | + |
| 33 | +::: |
| 34 | + |
| 35 | +## Default expanded and default checked |
| 36 | + |
| 37 | +Tree nodes can be initially expanded or checked |
| 38 | + |
| 39 | +:::demo Use `default-expanded-keys` and `default-checked-keys` to set initially expanded and initially checked nodes respectively. |
| 40 | + |
| 41 | +tree-v2/default-state |
| 42 | + |
| 43 | +::: |
| 44 | + |
| 45 | +## Custom node content |
| 46 | + |
| 47 | +The content of tree nodes can be customized, so you can add icons or buttons as you will |
| 48 | + |
| 49 | +:::demo |
| 50 | + |
| 51 | +tree-v2/custom-node |
| 52 | + |
| 53 | +::: |
| 54 | + |
| 55 | +## Tree node filtering |
| 56 | + |
| 57 | +Tree nodes can be filtered |
| 58 | + |
| 59 | +:::demo Invoke the `filter` method of the Tree instance to filter tree nodes. Its parameter is the filtering keyword. Note that for it to work, `filter-node-method` is required, and its value is the filtering method. |
| 60 | + |
| 61 | +tree-v2/filter |
| 62 | + |
| 63 | +::: |
| 64 | + |
| 65 | +## Attributes |
| 66 | + |
| 67 | +| Attribute | Description | Type | Default | |
| 68 | +| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------- | |
| 69 | +| data | tree data | array | — | |
| 70 | +| empty-text | text displayed when data is void | string | — | |
| 71 | +| props | configuration options, see the following table | object | — | |
| 72 | +| highlight-current | whether current node is highlighted | boolean | false | |
| 73 | +| expand-on-click-node | whether to expand or collapse node when clicking on the node, if false, then expand or collapse node only when clicking on the arrow icon. | boolean | true | |
| 74 | +| check-on-click-node | whether to check or uncheck node when clicking on the node, if false, the node can only be checked or unchecked by clicking on the checkbox. | boolean | false | |
| 75 | +| default-expanded-keys | array of keys of initially expanded nodes | array | — | |
| 76 | +| show-checkbox | whether node is selectable | boolean | false | |
| 77 | +| check-strictly | whether checked state of a node not affects its father and child nodes when `show-checkbox` is `true` | boolean | false | |
| 78 | +| default-checked-keys | array of keys of initially checked nodes | array | — | |
| 79 | +| current-node-key | key of initially selected node | string, number | — | |
| 80 | +| filter-method | this function will be executed on each node when use filter method. if return `false`, tree node will be hidden. | Function(value, data) | — | |
| 81 | +| indent | horizontal indentation of nodes in adjacent levels in pixels | number | 16 | |
| 82 | +| icon | custome tree node icon | string | - | |
| 83 | + |
| 84 | +## props |
| 85 | + |
| 86 | +| Attribute | Description | Type | Default | |
| 87 | +| --------- | ------------------------------------------------------------------------------------ | -------------- | -------- | |
| 88 | +| id | unique identity key name for nodes, its value should be unique across the whole tree | string, number | id | |
| 89 | +| label | specify which key of node object is used as the node's label | string | label | |
| 90 | +| children | specify which node object is used as the node's subtree | string | children | |
| 91 | +| disabled | specify which key of node object represents if node's checkbox is disabled | boolean | disabled | |
| 92 | + |
| 93 | +## Method |
| 94 | + |
| 95 | +`Tree` has the following method, which returns the currently selected array of nodes. |
| 96 | +| Method | Description | Parameters | |
| 97 | +| --------------- | ---------------------------------------- | ---------------------------------------- | |
| 98 | +| filter | filter all tree nodes, filtered nodes will be hidden | (query: string) | |
| 99 | +| getCheckedNodes | If the node can be selected (`show-checkbox` is `true`), it returns the currently selected array of nodes | (leafOnly: boolean) | |
| 100 | +| getCheckedKeys | If the node can be selected (`show-checkbox` is `true`), it returns the currently selected array of node's keys | (leafOnly: boolean) | |
| 101 | +| setCheckedKeys | set certain nodes to be checked | (keys: TreeKey[]) | |
| 102 | +| setChecked | set node to be checked or not | (key: TreeKey, checked: boolean) | |
| 103 | +| getHalfCheckedNodes | If the node can be selected (`show-checkbox` is `true`), it returns the currently half selected array of nodes | - | |
| 104 | +| getHalfCheckedKeys | If the node can be selected (`show-checkbox` is `true`), it returns the currently half selected array of node's keys | - | |
| 105 | +| getCurrentKey | return the highlight node's key (undefined if no node is highlighted) | — | |
| 106 | +| getCurrentNode | return the highlight node's data (undefined if no node is highlighted) | — | |
| 107 | +| setCurrentKey | set highlighted node by key | (key: TreeKey) | |
| 108 | +| setData | When the data is very large, using reactive data will cause the poor performance, so we provide a way to avoid this situation | (data: TreeData) | |
| 109 | + |
| 110 | +## Events |
| 111 | + |
| 112 | +| Event Name | Description | Parameters | |
| 113 | +| ---------------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | |
| 114 | +| node-click | triggers when a node is clicked | (data: TreeNodeData, node: TreeNode) | |
| 115 | +| node-contextmenu | triggers when a node is clicked by right button | (e: Event, data: TreeNodeData, node: TreeNode) | |
| 116 | +| check-change | triggers when the selected state of the node changes | (data: TreeNodeData, checked: boolean) | |
| 117 | +| check | triggers after clicking the checkbox of a node | (data: TreeNodeData, info: { checkedKeys: TreeKey[],checkedNodes: TreeData, halfCheckedKeys: TreeKey[], halfCheckedNodes: TreeData,}) | |
| 118 | +| current-change | triggers when current node changes | (data: TreeNodeData, node: TreeNode) | |
| 119 | +| node-expand | triggers when current node open | (data: TreeNodeData, node: TreeNode) | |
| 120 | +| node-collapse | triggers when current node close | (data: TreeNodeData, node: TreeNode) | |
| 121 | + |
| 122 | +## Slots |
| 123 | + |
| 124 | +| Name | Description | |
| 125 | +| ---- | -------------------------------------------------------------------------------------------- | |
| 126 | +| — | Custom content for tree nodes. The scope parameter is { node: TreeNode, data: TreeNodeData } | |
0 commit comments