We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Treeview getCheckedNodes() doesn't always return parent nodes...

When calling getCheckedNodes() with a fully selected treeview, all nodes are returned.

However if one of the children nodes is NOT selected (as seen below)

The top most node and its immediate child are NOT returned.
I assume this works as intended, but I need to get those top nodes returned.

How can I get all nodes returned that have a check mark or a square in them??

3 Replies

AB Ashokkumar Balasubramanian Syncfusion Team January 11, 2017 01:52 PM UTC

Hi Marc, 
We are unable to check the provided screenshot, since it is unclear. However, we can understand your requirement to retrieve the nodes which have checked and Indeterminate state. You can get only the checked nodes using the method "getCheckedNodes". To get both checked and Indeterminate node, please use the below code in your application instead of getCheckedNodes method. 

// TreeView control object creation  

var treeViewObj = $("#treeView").ejTreeView("instance"); 
// To get both checked and Indeterminate node 
var nodes = treeViewObj._liList.find('> div > .e-chkbox-wrap[aria-checked="mixed"],> div > .e-chkbox-wrap[aria-checked="true"]').closest('.e-item'); 

For your reference, we have prepared sample with your requirement, it can be downloaded from below location. 

Please let us know, if you require any further assistance. 

Ashokkumar B. 

AN Antonio July 23, 2020 10:10 PM UTC

How can i do the same thing in Angular 9 using Essential Javascript 2 and with latest version?

MK Muthukrishnan Kandasamy Syncfusion Team July 24, 2020 07:17 AM UTC

Hi Antonio, 
Thanks for contacting Syncfusion support. 
We can get the all checked nodes including the intermediate state in TreeView component. We have prepared TreeView sample in Angular 9 to meet your requirement, in this sample we get the all the checked and mixed state check box in the TreeView component. we can get the tree node data by using getNode method. Please refer to the below code block. 

btnClick() { 
      let allNode = document.querySelectorAll(".e-control.e-treeview .e-checkbox-wrapper[aria-checked='mixed'], .e-checkbox-wrapper[aria-checked='true']"); 
      let checked = []; 
      for (let i=0;i<allNode.length; i++){ 
        // get element 
        let node = allNode[i].closest(".e-list-item"); 
        // get node data 
        let nodeId = this.tree.getNode(node).id; 
Please refer to the below link for the sample. 
Getting started 
Tree node operation 
API documentation 
Please let us know, if you need any further assistance. 
Muthukrishnan K 

Live Chat Icon For mobile
Up arrow icon