Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Finding parent record in TreeGrid

    I have a TreeGrid with certain items duplicated under several different parent records. The action to take for a given item will depend partly on the parent of the item. However, I can't seem to figure out how, given a selected record, to find its parent. So, given:

    Code:
    var selectedRecord=MyTree.selection.getSelection()[0];
    How do I find the parent of selectedRecord? I could use MyTree.getRecord(id) but that method seems to be looking for a zero-based index of the parent record. How do I get that index? I can get the ParentID field of selectedRecord but I can't figure out how to use it to find the parent record since the ParentID foreign key doesn't necessarily match the zero-based record indices.

    #2
    Use tree.getParent. The Tree object - which is the data model for the TreeGrid - is accessible as MyTree.data.

    Comment


      #3
      Aha! I found a solution.

      tree.getParent works fine if, say, I'm in a nodeClick() function where I can just say:

      Code:
      MyMenu.data.getParent(node);
      But I need to use it from a function that isn't passed a node. It just finds the selected record (which isn't a TreeNode object and so can't be passed to getParent()). So here's how I did it:

      Code:
      var selected=MyMenu.getSelectedRecord();
      var parent=selected[MyMenu.data.parentProperty];
      Then, the "parent" variable holds the parent record of the selected record.

      Comment


        #4
        Nice job finding an alternate route, however, "selected" is actually a TreeNode. Anywhere you are looking at a TreeGrid method inherited from the ListGrid, you can read "ListGridRecord" as TreeNode.

        If there's anywhere in the docs you think this equivalence could be more clearly spelled out, please let us know.

        Also, thanks for chiming in on the thread about tabs :)

        Comment

        Working...
        X