How to expand/collapse the TreeGrid rows at specific hierarchical levels in JavaScript?
It is possible to expand and collapse the records at a specific hierarchical level in JavaScript TreeGrid, by using the expandAtLevel and collapseAtLevel public methods,
The below code example explains about how to expand and collapse records at specific levels
<div id="TreeGridContainer" style="height:400px;width:100%"></div> <button onclick="expand()" style="margin-top:10px">Expand</button> <button onclick="collapse()" style="margin-top:10px">Collapse</button> <script type="text/javascript"> $(function () { $("#TreeGridContainer").ejTreeGrid({ //... dataSource: projectData, enableCollapseAll: true, }) }); function expand() { var treeObj = $("#TreeGridContainer").data("ejTreeGrid"); //To expand the records at specific level, we need to pass the hierarchy level as method parameter treeObj.expandAtLevel(2); } function collapse() { var treeObj = $("#TreeGridContainer").data("ejTreeGrid"); //To collapse the record at specific level, we need to pass the specific hierarchy level as method parameter. treeObj.collapseAtLevel(1); } </script>
Sample to expand/collapse records at particular level is available in the following link,
Conclusion
I hope you enjoyed learning about how to custo expand/collapse the TreeGrid rows at specific hierarchical levels in JavaScript.
You can refer to our JavaScript TreeGrid 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 TreeGrid 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!