Basic
Introducing
API provides a set of functions for advanced work with the tree: add/remove tree node, searching, changing state and so on.
It is divided into 2 parts for several reasons:
for reducing the weight of the component
a separate API has more features that are not very often needed in the work
Connection
The connection of the API is very easy. The component has a property onReady. It calls right after componentDidMount call. The API object is passed as the first argument to the onReady function.
class AwesomeComponent extends React.PureComponent {
treeApi = null
handleTreeReady = (treeApi) => {
this.treeApi = treeApi
}
render() {
return <EyzyTree
data={data}
onReady={this.handleTreeReady}
/>
}
}Methods
find
Description: Finds nodes by specified Query
Arguments:
query: Query
Returns:
TreeNodenullif node is not found
Usage:
findAll
Description: Similar to
findmethod. But it returns all found nodes.Arguments:
query: Query
Returns:
Array<TreeNode>
Usage:
selected
Description: Returns selected nodes. Simple.
Returns: Result can be different depends on mode (multiple or single). See Component props
Single mode:
TreeNodeornullMultiple mode: array of
TreeNode. It will be always an array.
Usage:
Single mode:
Multiple mode:
checked
Description: For
checkablemode the library will combine checked nodes into an array. There are different ways to select "checked" nodes by usingvalueConsistsOfargument.ALL(default) it will gather all "checked" nodesBRANCHif node has children and it is checked (and all of the children nodes are checked) then all children nodes will be excluded from the resultLEAFreturns nodes which doesn't has children nodesWITH_INDETERMINATEthe same asALLplus indeterminate nodes
Arguments:
valueConsistsOf: 'ALL' | 'BRANCH' | 'LEAF' | 'WITH_INDETERMINATE'showDisabled: boolean (default false)
Returns:
Array<TreeNode>
Usage:
set
Description: Set any property to node. This method use
findmethod from the API. So it will apply changes only for the first match.Arguments:
criteriaFind criteriapropName: node of a property (ex: expanded, disabled and so on)propValue
Returns:
boolean
Usage:
To apply changes for all matches use next snippet:
data
Description: It is getter/setter for the
dataproperty of the node.Arguments:
query: Querykey: string | objectvalue: any (not required)
Returns:
undefineddata objectTreeNode
Usage:
addClass
Description: It will add classNames for the node. This class will be added to the node with the class
.node-content(check Node's structure)Arguments:
query: QueryArray<className>: string[]
Returns:
TreeNodeif node is foundnullif node is not found
Usage:
removeClass
Description: The same behavior as
addClassmethod, but it removes classNamesArguments:
query: QueryArray<className>: string[]
Returns:
TreeNodeif node is foundnullif node is not found
Usage:
hasClass
Description: Checks if a node has a
classNameArguments:
query: QueryclassName: string
Returns:
boolean
Usage:
append
Description: Inserts nodes to the end of the matched node
Arguments:
query: Querynodes: string | object | Promiseopts: Insertion options
Returns:
Promiselike<TreeNode[]>added nodes (always an array)nullif node is not found
Usage:
prepend
Description: This method is similar to
append. But nodes inserting to the beginning of children list. (well ... you know, as well as jQuery :) )Example:
before
Description: This method is similar to
append. But nodes inserting before matched node.Example:
after
Description: This method is similar to
append. But nodes inserting after matched node.
remove
Description: It removes matched node.
Arguments:
query: Query
Returns:
TreeNoderemoved nodenullif node is not found
Usage:
uncheckAll
Description: Set for all checked nodes unchecked states
unselectAll
Description: Removes selection for all selected nodes
toArray
Description: Returns list of nodes.
Last updated