Announcement

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

    TreeGrid, unable to fetch entire branch on folder open.

    Been at it for hours. Probably missing something simple. I am trying to open a folder to force it to fetch the entire branch of the tree. Tree is loaded on demand.

    I tried few different options, I created the following recursive method. Then I realized that data is fetched asynchronously so I implemented recursive call using treeGrid.addFolderOpenedHandler(). My problem is that tree.openFolder(node) does not trigger FolderOpenedEvent.

    Code:
    loadBranch(groupsTreeGrid, droppedRecord);
    
    public void loadBranch(TreeGrid treeGrid, TreeNode node){
        Tree tree = treeGrid.getData();  //tried treeGrid.getTree() as well
        tree.openFolder(node);
        TreeNode[] treeNodes = tree.getOpenList(node);
        for(TreeNode treeNode : treeNodes){
            if(!treeNode.getAttribute("id").equalsIgnoreCase(node.getAttribute("id"))) //ignore self
                loadBranch(treeGrid, treeNode);
        }
    }
    Here is the implementation of the event handler:
    Code:
    treeGrid.addFolderOpenedHandler(new FolderOpenedHandler() {
        @Override
        public void onFolderOpened(FolderOpenedEvent folderOpenedEvent) {
            Tree tree = treeGrid.getData();
            TreeNode[] treeNodes = tree.getOpenList(folderOpenedEvent.getNode());
            for(TreeNode treeNode : treeNodes){
                if(!treeNode.getAttribute("id").equalsIgnoreCase(folderOpenedEvent.getNode().getAttribute("id")))
                    tree.openAll(treeNode);
            }
        }
    });
    Maybe I am just going down the wrong path. Is there a sample somewhere which allows to open all folders within the branch by simply opening the first one. I don't really need to see the folder opened in the UI, but I do need to have the branch fetched. The bottom line is that I need to get TreeNode[] of the entire branch but all Tree methods to getLeaves() and getFolders() only operate on already loaded data thus I am trying to get it all loaded first.

    thanks,
    Henry

    #2
    I still can't figure this out. Perhaps if I restate the question, it'll make sense to someone who might point me in the right direction.

    How do I open a multi-level tree node in its entirety, not just its immediate children but its children's children and so on.

    thanks.

    Comment


      #3
      How are you generating the tree data?
      You need to provide a flattened list of all the children, including id/parentId values. Have you read the section of the javadocs related to "multi-level load on demand"?
      http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/docs/TreeDataBinding.html

      I haven't tried it myself, but it looks like you have to override the DSRequest operation that gets the tree data.

      Another option may be to implement the dataChangedHandler of the Tree:
      http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/widgets/tree/HasDataChangedHandlers.html

      Comment


        #4
        Thanks Joe, yes, I read the docs and the tree data is working perfectly and fetching data incrementally from the UI events. I click on a folder, I can see a fetch and folders opens up just fine and all subfolders and leafs displayed correctly. Same works as I keep traversing the tree through subfolders with the mouse clicks. The only thing that doesn't work is when i try the same only programatically. I even tried to fireEvent() but that just caused some weird exception having to do with null object.
        Code:
        groupsTreeGrid.fireEvent(new FolderOpenedEvent(droppedRecord.getJsObj()));
        This is triggered from the tree grid where the folder is being dropped to. Essentially, I need to perform a branch fetch after it's dragged over to another tree. BTW, the other tree is not databound thus I can't fetch droppedRecord's children in there and so I am trying to do it on the source.

        Comment

        Working...
        X