Unique node values

5 posts, 1 answers
  1. Jure
    Jure avatar
    15 posts
    Member since:
    Aug 2008

    Posted 30 Sep 2008 Link to this post

    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...
  2. Answer
    Simon
    Admin
    Simon avatar
    2281 posts

    Posted 30 Sep 2008 Link to this post

    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.
  3. Jure
    Jure avatar
    15 posts
    Member since:
    Aug 2008

    Posted 30 Sep 2008 Link to this post

    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...
  4. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 03 Oct 2008 Link to this post

    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.
  5. Jure
    Jure avatar
    15 posts
    Member since:
    Aug 2008

    Posted 08 Oct 2008 Link to this post

    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.
Back to Top