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

Unique node values

4 Answers 93 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jure
Top achievements
Rank 2
Iron
Iron
Iron
Jure asked on 30 Sep 2008, 10:37 AM
Hi!

I've implemented the drag & drop from radGrid to radTreeView using one of the online examples. At the moment I'm using a hidden field for temporarily storing the node values. The problem is nodes use the values from DB and can appear multiple times in the tree and when I drag to a lower node with value that already exist, it's dropped on the first node with that value...

I could store the node value based on the tree structure (cobination of levels and indexes) and then save the DB values to node's text but I'm wondering if there's a more elegant way, like some kind of internal node value that's unique? Like ID (node.get_ID() won't work) or something...

4 Answers, 1 is accepted

Sort by
0
Accepted
Simon
Telerik team
answered on 30 Sep 2008, 12:20 PM
Hi Jure,

You can use the _getHierarchicalIndex() function of the client-side Node object to get its unique index in the context of its parent TreeView.

I hope this is useful in your configuration.

Kind regards,
Simon
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jure
Top achievements
Rank 2
Iron
Iron
Iron
answered on 30 Sep 2008, 01:01 PM
Hi Simon, thanks for the fast reply!

By the time you posted I wrote my exact same javascript function, except that I use the "_" deliminator . I didn't find the suggested function in the documentation. ;) I then wrote a server side function to get the node based on the parsed returned hidden field value. It works but JavaScript would be better. If you have time...
0
Simon
Telerik team
answered on 03 Oct 2008, 10:53 AM
Hello Jure,

It would be great if you could share the function which gets the hierarchical index of a Node with the community.

And below is the 'opposite' JS function which finds a Node by its hierarchical index:
        function findNodeByHierarchicalIndex(treeView, hierarchicalIndex) { 
            var node = null
             
            var indeces = hierarchicalIndex.split('_'); 
            var nodes = treeView.get_nodes(); 
             
            for (var index = 0; index < indeces.length; index++) { 
                node = nodes.getNode(indeces[index]); 
                 
                if (node) { 
                    nodes = node.get_nodes(); 
                } 
                else { 
                    break
                } 
            } 
             
            return node; 
        } 

I hope it helps.

Best wishes,
Simon
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jure
Top achievements
Rank 2
Iron
Iron
Iron
answered on 08 Oct 2008, 09:06 AM
Hi Simon, sorry for the delay...

Here's my function, I stole bits from the documentation as I remember:

                 function getNodeHierarchy(node)
                {
                    //get the node hierarchy
                    
                    var s = node.get_index();
                    var currentObject = node.get_parent();
                    
                    while (currentObject != null)
                    {
                        // get_parent() will return null when we reach the treeview
                        if (currentObject.get_parent() != null)
                        {
                            s = currentObject.get_index() + "_" + s;
                        }
                        currentObject = currentObject.get_parent();
                    }
                    
                    return s;
                }

Thanks for yours, will try to use it.
Tags
TreeView
Asked by
Jure
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Simon
Telerik team
Jure
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or