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

Most methods accept a Query argument. Full description: Query

find

  • Description: Finds nodes by specified Query

  • Arguments:

  • Returns:

    • TreeNode

    • null if node is not found

  • Usage:

findAll

  • Description: Similar to find method. But it returns all found nodes.

  • Arguments:

  • 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: TreeNode or null

    • Multiple mode: array of TreeNode. It will be always an array.

  • Usage:

Single mode:

Multiple mode:

For a tree in multi-selection mode the selected method returns always an array. It does not matter if the selected nodes or not.

checked

  • Description: For checkable mode the library will combine checked nodes into an array. There are different ways to select "checked" nodes by using valueConsistsOf argument.

    • ALL (default) it will gather all "checked" nodes

    • BRANCH if node has children and it is checked (and all of the children nodes are checked) then all children nodes will be excluded from the result

    • LEAF returns nodes which doesn't has children nodes

    • WITH_INDETERMINATE the same as ALLplus indeterminate nodes

  • Arguments:

    • valueConsistsOf: 'ALL' | 'BRANCH' | 'LEAF' | 'WITH_INDETERMINATE'

    • showDisabled: boolean (default false)

  • Returns:

    • Array<TreeNode>

  • Usage:

set

It is not recommended to use this method.

  • Description: Set any property to node. This method use find method from the API. So it will apply changes only for the first match.

  • Arguments:

    • criteria Find criteria

    • propName: node of a property (ex: expanded, disabled and so on)

    • propValue

  • Returns:

    • boolean

  • Usage:

To apply changes for all matches use next snippet:

data

You can store here whatever you want.

  • Description: It is getter/setter for the data property of the node.

  • Arguments:

    • query: Query

    • key: string | object

    • value : any (not required)

  • Returns:

    • undefined

    • data object

    • TreeNode

  • Usage:

This method has different return results

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: Query

    • Array<className>: string[]

  • Returns:

    • TreeNode if node is found

    • null if node is not found

  • Usage:

removeClass

  • Description: The same behavior as addClass method, but it removes classNames

  • Arguments:

    • query: Query

    • Array<className>: string[]

  • Returns:

    • TreeNode if node is found

    • null if node is not found

  • Usage:

hasClass

  • Description: Checks if a node has a className

  • Arguments:

    • query: Query

    • className: string

  • Returns:

    • boolean

  • Usage:

append

  • Description: Inserts nodes to the end of the matched node

  • Arguments:

  • Returns:

    • Promiselike<TreeNode[]> added nodes (always an array)

    • null if 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:

  • Returns:

    • TreeNode removed node

    • null if 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