This is a migrated thread and some comments may be shown as answers.

[Solved] checkNode() creates duplicate tree nodes

1 Answer 86 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jonathan
Top achievements
Rank 1
Jonathan asked on 06 Oct 2011, 05:54 PM
Hi all,

I am trying to create a tree view that remembers it's state (e.g. what items have been expanded/checked etc.) by storing node values in a cookie. When I initially load the tree view and restore it's state I have no issues, however I am experiencing problems after the tree has been restored.

If I check a collapsed node in the tree view and then expand it (uses an AJAX call to server) the child nodes are duplicated. Using firebug I can confirm the following is not happening:

- Double server call
- Double JSON value being returned

This has lead me here, since I'm starting to think there could be an issue with the tree view itself?

Here is my code to handle the onCheck() callback:

_onChecked = function (e) {
            var t = element.data('tTreeView');
 
            // Get Parent and Child Nodes to check
            var parentNodeID = t.getItemValue(e.item);
            var childNodes = $(e.item).find('li');
 
            // Add the nodes to check to an array,
            // this array is added to the state cookie
            var nodesToCheck = [];
            nodesToCheck.push(parentNodeID);
 
            // All children nodes must have the same checked value as their parent
            var parentCheckValue =
                $(e.item).find('div:first > span[class="t-checkbox"] > input[type="checkbox"]').is(':checked');
 
            if (childNodes.length > 0) {
                $(childNodes).each(function (i, v) {
                    var nodeID = $(v).find('div:first > input[type="hidden"]').val();
 
                    // Check the node
                    t.nodeCheck(v, parentCheckValue);
 
                    // Add node to state array
                    nodesToCheck.push(nodeID);
                })
            }
 
            // Send state array to Node Manager to store node state in cookie
            NodeManager.checkNodes(nodesToCheck);
        };

Let me know if you need anymore info. Any help is greatly appreciated.

Thanks.

1 Answer, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 07 Oct 2011, 06:45 AM
Hello Jonathan,

There doesn't seem to be anything wrong with the code you sent. However, have in mind that if a node has subnodes and makes an AJAX call to the server, it will get its childnodes doubled. The old childnodes are not removed in order to handle scenarios where the user drag&drops a node onto a LoadOnDemand node that isn't fetched from the server. Therefore, please ensure that you aren't explicitly triggering the AJAX request of the given node.

If the problem persists, please supply a sample project that shows the issue.

Greetings,
Alex Gyoshev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
TreeView
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Share this question
or