Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have Only one node (chekbox) selected at a time #44

Open
c623700 opened this issue May 21, 2020 · 0 comments
Open

Have Only one node (chekbox) selected at a time #44

c623700 opened this issue May 21, 2020 · 0 comments

Comments

@c623700
Copy link

c623700 commented May 21, 2020

I try to force the list of nodes to only have one "isChecked" node by calling a function that would update the data from the onCheckToggleCb but to no avail.
here is the code:
<SuperTreeview
....
onCheckToggleCb={(arrayOfNodes, depth)=>{
this.handleCheck(arrayOfNodes);
....
/>

handleCheck(arrayOfNodes) {
    const isChecked = arrayOfNodes[0].isChecked;
    const nodeId = arrayOfNodes[0].id;
    var data = this.state.data;

    // if the node is being unchecked, leave data alone (it will update itself)
    if (isChecked) {
        // if the node is being checked, "wipe out" all the "checked" node in this.state.data (should be only one)
        applyCheckStateTo(data, nodeId);

        // Set the updated data in this.state.data
        this.setState({data: data});
    }

    function applyCheckStateTo(data, nodeId){
        data.forEach((node)=>{
            if (node.id != nodeId)
                node.isChecked = false;
            else
                node.isChecked = true;
            if(node.children){
                applyCheckStateTo(node.children, nodeId);
            }
        })
    }
}

Previous response suggested that is any properties need to be modified, it can be done on the onUpdateCb function, but how do I know (from onUpdateCb) which node to leave check and which node to uncheck as "arrayOfNodes is Not pass to onUpdateCb.

Appreciate any help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant