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 enable CheckBoxs only in child nodes

Hi all,

I'm using 'ejs-treeview' component to load parent & child data. Designer code as below,

[animation]='animation' (nodeChecked)='nodeChecked($event)' [showCheckBox]='showCheckBox'>


According to the above code, it will generate TreeView including CheckBoxes with parent node CheckBoxes. My requirement is, CheckBoxes should be
load only in Child nodes. Sample control designer as below. (Note: This sample made by designing tool)


My second requirement is, when we checking on the 'N2 Child 4' node, all other parent child nodes should be unchecked & when we checking on any other
child node that 'N2 Child 4' node should be unchecked. These requirements are highly important to me and highly appreciate if can be achieved.

Thank you


1 Reply

CI Christopher Issac Sunder K Syncfusion Team March 4, 2019 12:24 PM UTC

Hi Shamil, 

Thank you for contacting Syncfusion support. 

We have analyzed your requirements and prepared a sample based on that. 
 
Query-1: Checkboxes should be enabled only in child nodes 
For this case, you can disable the check box for the parent node in the created event of treeview. Please find the code snippet 

let liEle = this.treevalidate.element.querySelectorAll('li'); 
for (let i = 0; i < liEle.length; i++) { 
    if (liEle[i].classList.contains('e-level-1')) { 
        let element = liEle[i].querySelector('.e-checkbox-wrapper'); 
        if (element) 
            element.parentElement.removeChild(element); 
    } 
    this.treevalidate.checkAll(); 
    this.treevalidate.uncheckAll(['11']); 
} 
 
Query-2: Checking the last child node 'N2 Child 4' should uncheck all other parent child nodes . 
You can achieve this in the nodeChecking event of treeview. 

We have prepared the sample by considering the 'N2 Child 4' node. Please check the sample and let us know whether it fulfills your requirement. 

Please let us know if you require any further assistance. 

Thanks, 
Christo

Loader.
Live Chat Icon For mobile
Up arrow icon