How to get parent id of treepanel selected node)

  1. #1

    How to get parent id of treepanel selected node)

    Hi,

    I've been spending hours to get parent id of currently selected node of a treepanel. I could find the parent in server side but, couldn't convert it to node type. I need an urgent reply... Here you can see my codes.

                                          if(#{tpPotentialAndTargetInfo}.getSelectionModel().hasSelection())
                                            {
                                                var nodeId = #{tpPotentialAndTargetInfo}.getSelectionModel().getSelection()[0].data.id;
                                             
                                                #{DirectMethods}.UpdatePotentialAndTarget(nodeId);
                                                
                                            }
    [DirectMethod]
            public void UpdatePotentialAndTarget(string id)
            {
               var subCategory= tpPotentialAndTargetInfo.GetNodeById(id); // this code returns nodeproxy.
               var category = subCategory.ParentNode();
               var mainCategory = category.ParentNode();
               var puarId = mainCategory.ParentNode();
            }
    Last edited by Daniil; Feb 11, 2013 at 4:56 AM. Reason: Please use [CODE] tags
  2. #2
    Hi @ozlem,

    Send a parent node's id as an additional parameter of a DirectMethod.

    A NodeProxy does know nothing about its parent.
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @ozlem,

    Send a parent node's id as an additional parameter of a DirectMethod.

    A NodeProxy does know nothing about its parent.

    Thanks for your answer. I solved the problem. Here you can see my codes.

    
    var subCategory=#{tpPotentialAndTargetInfo}.getSelectionModel().getSelection()[0];
    var subCategorıId=subCategory.data.id;
    var category=subCategory.parentNode;
    var categoryId=category.data.id;
    
    #{DirectMethods}.UpdatePotentialAndTarget(subCategoryId,categoryId);
    Last edited by Daniil; Feb 14, 2013 at 9:52 AM. Reason: Corrected the [CODE] tags
  4. #4
    Thank you for sharing a solution. It can help someone on the forums in the future.
  5. #5
    But there is no way to find parent NodeID from code behind in event not related with treeview.

    When use

    Tree.SelectedNodes(0). there is no ParentID or Parent anything...

    If use Tree.GetNodeById or Tree.SelectedNodes(0).ToProxyNode.ParentNode

    you CAN go to Parent but you can not do anything with it because there in no way to read name/text/id/anything useful.

    So either you have node without parent property or you have NodeProxy parent which is useless.

Similar Threads

  1. Replies: 11
    Last Post: Feb 06, 2013, 5:09 PM
  2. Replies: 16
    Last Post: Jul 19, 2011, 3:53 AM
  3. Replies: 1
    Last Post: Nov 24, 2010, 3:04 PM
  4. Treepanel - Set Selected Node
    By Tbaseflug in forum 1.x Help
    Replies: 2
    Last Post: Dec 01, 2009, 4:46 PM
  5. Treepanel - get child values of selected parent
    By Tbaseflug in forum 1.x Help
    Replies: 2
    Last Post: Nov 10, 2009, 11:28 AM

Posting Permissions