How to programmatically check a node

Hi. I am using the TreeView component with a Hierarchical data binding and the 'showCheckBox' property set to true.

When I open the tree view page, I need to set some nodes as checked and of course display it in the relative checkbox. How can I do?

I saw that there is the possibility to check all nodes (with the checkAll () method), but I only have to check some of them. Besides, even when I use the checkAll () method, I don't see the checkboxes of all the nodes checked.

Could you give me a simple example of how I can realize this need of mine?

Thanks for your help


8 Replies 1 reply marked as answer

IL Indhumathy Loganathan Syncfusion Team February 28, 2022 10:25 AM UTC

Hi Alfredo, 
 
Greetings from Syncfusion support. 
 
In the TreeView component, we have a built-in property called isChecked. By enabling that property in the datasource you can check required nodes at initial rendering.  
 
Please, refer the below code snippet.  
 
public field: Object = { 
    dataSource: this.countries, 
    id: 'id', 
    parentID: 'pid', 
    text: 'name', 
    hasChildren: 'hasChild', 
    isChecked: 'isChecked', 
}; 
 
{ id: 7, name: 'Brazil', hasChild: true, isChecked: true }, 
 
 
 
You can also check required nodes dynamically by passing an array of id values as an argument to the checkAll Method. 
   
Please let us know if you need any further assistance.   
  
Regards, 
Indhumathy L


AL Alfredo February 28, 2022 07:31 PM UTC

Thanks for the reply.
Unfortunately, the information you gave me relates to the so-called 'Self-referential Data' local binding. I have used this binding system in the past and have had no problems.
Today, however, I am using the local binding called 'Hierarchical data' and it is with this system that I have problems. Could you be kind enough to give me an example of how to programmatically check a node for local binding 'Hierarchical data'?

 Thanks in advance


KR Keerthana Rajendran Syncfusion Team March 1, 2022 02:12 PM UTC

Hi Alfedro, 
 
You can programmatically check a node with hierarchical data by using checkedNodes property.  
 
<ejs-treeview id="tree" [fields]='fields' showCheckBox="true" [checkedNodes]="checkedNodes"></ejs-treeview> 
 
public checkedNodesstring[] = ['CUB''MEX']; 
 
 
Refer to the following links. 
 
 
 
Regards, 
Keerthana R. 


Marked as answer

AL Alfredo March 1, 2022 08:12 PM UTC

 



AL Alfredo replied to Keerthana Rajendran March 1, 2022 08:14 PM UTC

Ok.

You have been very kind and very helpful.

Thank you



KR Keerthana Rajendran Syncfusion Team March 2, 2022 06:25 AM UTC

  
Hi Alfredo, 

Most welcome. We are glad that the provided details helped you. Please get back to us if you need any further assistance, we will be happy to assist you. 

Regards, 
Keerthana R. 



RO RobertDupree replied to Indhumathy Loganathan November 4, 2022 06:18 AM UTC

Thanks for sharing.



KG Kristin Gore November 5, 2022 01:16 PM UTC

It looks so good as usual. I'm so much happy to know more about it here. Thanks for posting. 


Loader.
Up arrow icon