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.
Unfortunately, activation email could not send to your email. Please try again.

TreeView getSelectedNode() empty even if selected node checked.

Thread ID:

Created:

Updated:

Platform:

Replies:

127716 Dec 5,2016 01:09 AM Dec 13,2016 06:43 AM ASP.NET MVC 7
loading
Tags: TreeView
Juan Acosta
Asked On December 5, 2016 01:09 AM

Hi,

I have a Treeview that is populated with the viewBag.Data.

<div style="text-align:right;">
    <div style="display: inline-block;">
        @Html.EJ().TreeView("treeGeneralSecurityGroupMaintenance").TreeViewFields(s => s.Datasource((IEnumerable<DocTracerPortal.Models.Visual.VisualGroup>)ViewBag.groupsSourceGrid)
                .Id("id").ParentId("parentId").Text("name").HasChild("hasChild")).ShowCheckbox(true).AllowEditing(false).EnablePersistence(true).EnableRTL(true).LoadOnDemand(true).ClientSideEvents(e => e.NodeCheck("onItemSelectGroupsGeneralMaintenance")).ClientSideEvents(e => e.NodeUncheck("onItemSelectGroupsGeneralMaintenance"))
    </div>
</div>


Generally, the Treeview works fine.  However, I found some strange behaviour.

Sometimes, the getSelectedNode() functions simply return empty. Even if the Treeview have nodes selected.



In the previous image, the Treeview has the test developer node selected.
If I check the internal details of the Treeview the property  _CurrentSelectedNodes is fine with data.




This behaviour is erratic, I used the same code pieces to populated on demand the nodes. With other selections, it works perfect.

So, I'm not quite sure what could be the trigger for this behaviour.



Could you please tell what could be the problem.

Kind regards,

Juan Acosta

Juan Acosta
Replied On December 5, 2016 01:49 AM

I was checking the nodes received and they have the information properly mapped.



So, I think the issue is in the addNode function in js.

But,I don't why it could be happening.

Kind regards,
Juan

Piramanayagam Ramakrishnan [Syncfusion]
Replied On December 6, 2016 03:50 AM

Hi Juan, 
 
Thanks for contacting Syncfusion support. 
 
We have analyzed your query. We would like to inform you that, we can get the checked nodes by using getCheckedNodes method. This method return the all checked nodes of TreeView control. Please refer the below code sample, 
 
[Script] 
 
function getcheckednodes() { 
    var treeObj = $("#tree").data("ejTreeView"), nodetext = ""; 
    var nodes = treeObj.getCheckedNodes();//to get Checked nodes 
    console.log(nodes); 
    for (var i = 0; i < nodes.length; i++) { 
        nodetext += treeObj.getText($(nodes[i])) + ", "; //to get text of the given node 
    } 
    alert("Checked nodes are: " + nodetext); 
} 
 
 
For more details about the getCheckedNodes method then please refer the help document, 
 
For your reference, we have prepared a sample based on your requirement in the link: Sample 
 
Please let us know whether the provided sample is helpful in achieving your requirement. If not, get back to us with more information for us to assist you. 
 
Regards, 
Piramanayagam R

Juan Acosta
Replied On December 7, 2016 05:26 AM

Hi Piramanayagam,

I was checking the code that you passed to me and I was already using something similar.

function getAllSelectedNodesMaintenance() {
    console.log("getAllSelectedNodesMaintenance");
    treeObjGroup = $("#treeGeneralSecurityGroupMaintenance").ejTreeView('instance');
    //to get checkednodes
    var checkGroupNodes = treeObjGroup.getCheckedNodes();
    var checkAllGroupNodes = [];
    for (var i = 0; i < checkGroupNodes.length; i++) {
        checkAllGroupNodes.push(checkGroupNodes[i].id);
    }
    treeObjIndividual = $("#treeGeneralSecurityIndividualMaintenance").ejTreeView('instance');
    //to get checkednodes
    var checkIndividualNodes = treeObjIndividual.getCheckedNodes();
    for (var i = 0; i < checkIndividualNodes.length; i++) {
        checkAllGroupNodes.push(checkIndividualNodes[i].id);
    }
    return checkAllGroupNodes;
}


However, the issue is the same the treeView is marked and I cannot recover the checkedNode information.


The js console shows this.
 


As you can see, the length of the list of objects returned is 0.

There is any another way to recover the information in the nodes ?

I will be waiting for your reply.

Kind regards,

Juan


Juan Acosta
Replied On December 7, 2016 05:30 AM

By the way, you did not reply. Why if the getCheckedNodes() is 0 the _CurrentSelectedNode is 1?



So, what is happening with the control?

How can I activate the debug properties in the syncfusion controls? Well, you have debug options for the controls?

Kind regards,

Juan



Balamurugan P [Syncfusion]
Replied On December 8, 2016 08:52 AM

Hi Juan, 
Sorry for the Inconvenience caused. 
We have analyzed the reported issue with your code blocks; its working fine in our end. In our analysis, your reported case occurs, while unchecking the last remaining one checked node of TreeView. Here you will get the checked node details as empty, since you have unchecked the last node also. This is a correct behavior.  
 
Also we suggest you that don’t use our private properties “treeObjIndividual._CurrenctSelectedNodes”, since it won’t maintain the details properly. We recommend our public API’s that you can check this with our online API Documentation: https://help.syncfusion.com/api/js/ejtreeview   (Our EJMVC components are created as wrapper for the JavaScript components. So the API, and events will be the same in both JS and EJMVC components
 
As per our API documentation, you can get the checked node details in following ways. 
·         treeObjIndividual.model.checkedNodes  
 
Also, you can get the currently checked and unchecked node details innodeCheck”, “nodeUncheck” event arguments 
 
For your convenience we have prepared the simple sample based on this along with your code blocks and you can get it from following link. 
 
In case, if you face the same problem, please revert us by modifying the sample based on your application along with replication procedure and EJ script version and browser details. This would be helpful for us to serve you. 
Regards, 
Balamurugan

Juan Acosta
Replied On December 9, 2016 02:24 AM

Hi Balamurugan,

I will check if I can get the correct values using any of the other methods you suggested.

As a matter of fact, I got the issue when I repopulate the Treeview on demand depending on the changes in another dropdown .

In my opinion, the node details should not be empty. Because I repopulate the Treeview with complete details about the selected nodes with Ids and names.

The funny thing is if I rechecked the node with the issue with the mouse, the event populate the checked nodes with the proper values. So, That will mean the nodes are correctly populated. 

I will let you know if I can understand and reproduce the issue in your latest sample.

Kind regards,

Juan


Piramanayagam Ramakrishnan [Syncfusion]
Replied On December 13, 2016 06:43 AM

Hi Juan, 
 
Thanks for your update. 
 
We will wait to hear from you. Please share the more information along with below details, 
1.     How to expect state in TreeView after repopulate the TreeView on demand depending on the changes in another dropdown? Ie., if you want to maintain the initial checked states of TreeView after repopulate it then no need to use the EnablePersistence property in TreeView. 
2.     Repopulate the TreeView code. 
3.     Any simple sample or revert back the previously provided sample to reproduce issue in our end. 
 
These information would be helpful for us to identify the issue and provide a solution at the earliest. 
 
Regards, 
Piramanayagam R

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;