Articles in this section
Category / Section

How to expand and collapse the parent node on the checkbox click in the JavaScript Dropdown Tree component?

3 mins read

Use the JavaScript Dropdown Tree component's nodeChecked event to expand and collapse the parent node on the checkbox click in the JavaScript Dropdown Tree component. Inside this event, you can use the expandAll and collapseAll methods.


[index.js]

   …

    // Initialize the Dropdown Tree component.

    var checkList = new ej.dropdowns.DropDownTree({

        fields: { dataSource: dataSource.checkboxData, value: 'id', parentValue: 'pid', text: 'name', hasChildren: 'hasChild', },

        showCheckBox: true,

        placeholder: 'Select items',

        popupHeight: '200px',

        mode: 'Delimiter',

        treeSettings:{autoCheck: true}

    });

    checkList.appendTo('#ddtree');

    //Define the nodeChecked function.

    checkList.treeObj.nodeChecked = function(args){

        if( args.data[0].hasChildren && !args.data[0].expanded ){

            checkList.treeObj.expandAll(args.data[0].id);

        }

        else if( args.data[0].hasChildren && args.data[0].expanded){

            checkList.treeObj.collapseAll(args.data[0].id);

        }

    };


Refer to the following sample link: 


Conclusion

I hope you enjoyed learning about how to expand and collapse the parent node on the checkbox click in the JavaScript Dropdown Tree component.

How to expand and collapse the parent node on the checkbox click in the JavaScript Dropdown Tree component

You can refer to our JavaScript Dropdown Tree feature tour feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Dropdown example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!



Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied