Announcement

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

    ListGrid groupTree is not a ResultTree

    Hello Iso,

    I have encountered a slight complication with getGroupTree() method on a grouped listGrid.
    What I'm trying to accomplish is to save a state of opened folders (groups) of a grouped listgrid to reapply this state later on. I have found getOpenState() method in ResultTree class which seems to be exactly what I want.

    The issue I'm encountering is that my listGrid returs a Tree, not a ResultTree when getGroupTree() is called.
    In the docs it states that a ResultTree is returned if a DataSource is provided to the ListGrid . I do have a DataSource bound to a listGrid. The datasource is a clientOnly DS with defined dataSourceFields but it receives no data. Data are provided to the grid via ListGrid.setData().

    Is this why listGrid.getGroupTree() returns a Tree instead of a ResultTree?
    Even if I provide the data to the DS (either as DS.setTestData() or DS.addData()) a simple Tree is returned.

    Is there any way I can get ahold of a resultTree within this configuration?

    Thanks

    SmartGWT: SmartClient Version: v11.1p_2018-03-21/Pro Deployment (built 2018-03-21)
    Chrome: 67.0.3396.99

    EDIT: I'v just noticed that I'v probably posted this in the wrong forum section. Feel free to move this thread to SmartGWT Q&A if needed.
    Last edited by pavel.benes; 18 Jul 2018, 21:45.

    #2
    Hi pavel.benes,

    FYI: I made a suggestion for this as an enhancement here.

    Best regards
    Blama

    Comment


      #3
      Hi Blama ,
      Thanks for replying. I have just noticed that thread now but I am a bit perplexed by the lack of notion of the getOpenState() method I noted above.
      Is this not the solution to reopening folders from a saved snapshot? Or am I mistaken about what that method is intended to do?
      Last edited by pavel.benes; 18 Jul 2018, 04:54.

      Comment


        #4
        Hi pavel.benes, Hi Isomorphic,

        this sounds like a way to get the data and is the way Isomorphic suggests (without mentioning the API name) here.
        The thread is more about a handler to automatically get notified about changes and about including this in Viewstate-data.

        Best regards
        Blama

        Comment


          #5
          So in the meantime I tried to accomplish this by saving paths to open folders within the group tree.
          A slight issue is that nodes inside the groupTree get autoassigned names and these names do change with each groupBy. Therefore just saving these paths would be no use, since the path would not exist in the newly formed groupTree.
          So my idea to go around this was to assign a name to each folder node based on its "groupValue" attribute.

          Code:
          node.setName(node.getAttribute("groupValue"));
          This way, theoretically, every folder node should still have a unique path within the tree and within every new tree formed by the same grouping (given I assign the names to the tree's nodes again once it is formed anew).
          But as it turns out, even when a TreeNode has a "name" attribute assigned the path that is returned from Tree.getPath(node) still consists of autoAssigned names (eg. /0_0, /0_6, /0_12, ...) and not the names I have manually given to those nodes (the nodes still return the correct name I assigned to them if queried with node.getName(), though).
          Is this intended? In the docs for Tree.getPath() it states that a path has a format of ([name][pathDelim]?)*, why would the method not use the names of nodes I'v given them?

          So this leaves me empty handed. But still, I'd rather the getOpenState() on ResultTree approach was used than to try and reinvent the wheel...

          Here is the test case for the above issue if needed.

          Code:
          public void onModuleLoad() {
              ListGrid lg = new ListGrid();
              lg.setWidth100();
              lg.setHeight100();
              lg.setCanGroupBy(true);
              lg.setCanMultiGroup(true);
          
              ListGridField group = new ListGridField("group");
              ListGridField name = new ListGridField("name");
              ListGridField cost = new ListGridField("cost");
          
              lg.addGroupByCompleteHandler(new GroupByCompleteHandler() {
                  @Override
                  public void onGroupByComplete(GroupByCompleteEvent event) {
                      if(!lg.isGrouped())
                          return;
          
                      Tree groupTree = lg.getGroupTree();
                      TreeNode root = groupTree.getRoot();
                      root.setName("root");
                      root.setID("root");
                      giveNamesToChildGroupFolders(root, groupTree);
          
                      for(TreeNode node : groupTree.getAllNodes()) {
                          if(groupTree.isFolder(node)) {
                              GWT.log("node name: " + node.getName(), null);
                              GWT.log("node path: " + groupTree.getPath(node), null);
                          }
                      }
                  }
              });
          
              lg.setFields(group, name, cost);
              lg.setData(provideRecords());
          
              Button groupButton = new Button();
              groupButton.setTitle("Group by group");
              groupButton.addClickHandler(new ClickHandler() {
                  @Override
                  public void onClick(ClickEvent event) {
                      lg.groupBy("group");
                  }
              });
          
          
              VLayout layout = new VLayout();
              layout.setHeight100();
              layout.setWidth100();
              layout.setMembersMargin(5);
          
              HLayout buttonsLayout = new HLayout();
              buttonsLayout.setWidth100();
              buttonsLayout.setHeight(50);
              buttonsLayout.addMember(groupButton);
          
              layout.addMember(buttonsLayout);
              layout.addMember(lg);
              layout.draw();
          }
          
          
          private void giveNamesToChildGroupFolders(TreeNode parent, Tree tree) {
              if(parent == null || tree.getChildren(parent).length == 0)
                  return;
          
              for(TreeNode child : tree.getChildren(parent)) {
                  if(tree.isFolder(child)) {
                      child.setName(child.getAttribute("groupValue"));
                      child.setID(child.getName());
                      child.setParentID(parent.getName());
                      GWT.log( "child : " + child.getName() + " of a parent: " + parent.getName(), null);
                  }
                  if(tree.getChildren(child).length > 0)
                      giveNamesToChildGroupFolders(child, tree);
              }
          }
          
          private ListGridRecord[] provideRecords() {
              List<ListGridRecord> records = new ArrayList<>();
              for(int i=0; i<5; i++) {
                  ListGridRecord record = new ListGridRecord();
                  record.setAttribute("group", "Drinks");
                  record.setAttribute("name", "CocaCola " + i);
                  record.setAttribute("cost", "" + i);
                  records.add(record);
              }
              for(int i=0; i<5; i++) {
                  ListGridRecord record = new ListGridRecord();
                  record.setAttribute("group", "Meals");
                  record.setAttribute("name", "Spaghetti " + i);
                  record.setAttribute("cost", "" + i);
                  records.add(record);
              }
              for(int i=0; i<5; i++) {
                  ListGridRecord record = new ListGridRecord();
                  record.setAttribute("group", "Cutlery");
                  record.setAttribute("name", "Fork " + i);
                  record.setAttribute("cost", "" + i);
                  records.add(record);
              }
              return records.toArray(new ListGridRecord[0]);
          }
          Last edited by pavel.benes; 18 Jul 2018, 23:49.

          Comment


            #6
            Hello Isomorphic ,
            could I get any feedback regarding the returned tree of ListGrid().getGroupTree() not being a ResultTree within my configuration and whether there is a way I could make it work?

            Thanks in advance

            Comment


              #7
              Hi Isomorphic
              is there an official statement to the above described issue(s)?

              Thanks

              Comment


                #8
                The groupTree should not be a ResultTree because it does not do load on demand. It works with already-loaded data only.

                Tree has a getOpenList() API that will do what you need.

                Comment

                Working...
                X