Checking nodes programatically is not working

Hi,
I have defined a treeView and I am populating it with data from ajax call. In the same ajax call, I am getting datasource to the treeview  (result.myNodes), and ids to check nodes in the treeview (result.idsNodesToCheck). When I check content of result.idsNodesToCheck, I can see that it has numbers that belongs to the treeView nodes ids. I am using the next code but it is not checking the nodes, don´t know what I am doing wrong. I will appreciate your help.

<div id="myTreeView"></div>
<script>
$.ajax({
                    url: "/backoffice/GetNodes/?id=" + $("#IdPerfil").val(),
                    type: "GET",
                    cache: false,
                    success: function (result) {
                        if (result.succeed) {
                            $("#myTreeView").ejTreeView({
                                fields: {
                                    dataSource: result.myNodes,
                                    id: "IdFuncionesModulo",
                                    parentId: "IdFuncionPadre",
                                    text: "DescripcionFuncion"
                                },
                                showCheckbox: true,
                                allowMultiSelection: true,
                            });
                            var treeObj = $("#MyTreeView").ejTreeView('instance');
                            for (var i = 0; i < result.idsNodesToCheck.length; i++) {
                                treeObj.checkNode($("#" + i.toString()));
                            }
                            treeObj.refresh();
                        }
                        else {
                            NotyAviso('error', result.msg, false, true, false, true);
                        }
                    },
                    error: function (jqXHR, textStatus, error) {
                        NotyAviso('error', error, false, true, false, true);
                    }
                });
</script>

3 Replies

AB Ashokkumar Balasubramanian Syncfusion Team July 2, 2018 12:52 PM UTC

Hi Juan Jose Uribe,   
   
We have checked the reported problem with your provided code block. We suspect that, the corresponding checked nodes details (result.idsNodesToCheck) are not lost in ajax result data. Could you please ensure this at your end?    
   
Also, we don’t need to convert the id into element then pass it into checkNode method. checkNode method accepts array of id’s, so you can pass the node’s id directly to this method. Please check the below code block.   
   
[Script]   
 
  // checkedNodes data = [“2”,”3” ];   
 var treeObj = $("#myTree").ejTreeView('instance');   
 treeObj.checkNode(checkedNodes);   
   
Based on your scenario, we have prepared a sample. Please find the sample in below location.   
   
Sample:    
   
 
To know more details checkNode method, please check the below API document.   
   
   
If still you are facing the same problem, please share the below details.   
   
1.     Data Source ‘s data details   
2.     Passed checked node’s data details(idsNodesToCheck)   
   
Regards,   
Ashokkumar B.   



JJ Juan Jose Uribe July 3, 2018 02:51 PM UTC

Thanks so much,

The result.idsNodesToCheck is ok, ajax call is returning the data ok, the problem was the way I was checking the nodes with the for sentence instead of treeObj.checkNode(checkedNodes);. I change it and now it is working right.

Thanks again, kind regard,

Juan J.


AB Ashokkumar Balasubramanian Syncfusion Team July 5, 2018 07:08 AM UTC

Hi Juan, 
 
Most Welcome. 
 
Please let us know, if you need any further assistance. 
 
Regards, 
Ashokkumar B. 


Loader.
Up arrow icon