Announcement

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

    Issue with GroupTitleRenderer for grouped ListGrid

    I have many grouped grids where we set the group title based on the sums in that group.

    In order to do that, we basically make a call in fetchdata callback, take the group tree out, go through the nodes, and for each node find the "summary" child node and retrieve values from it.
    It works (see my code below), but lots of code, and unwieldy. I therefor looked into the "GroupTitleRenderer" interface.

    The method that is called is:
    Code:
    public String getGroupTitle(Object title, GroupNode groupNode, ListGridField listGridField, String groupByField, ListGrid listGrid)
    However, I cannot find any way to directly get at the "groupsummary" node for the group from within the method. My questions therefore are:


    1. You agree that the grouptitlerenderer is a good way forward?
    2. In that case, how on earth do i get at the group summary node from within the grouptitlerenderer?

    Thanks in advance, see my current way of fetching the group summary field below.


    Code:
        public void updateHeadersForGroupedGrid(ListGrid groupedGrid) {
            Tree tree = groupedGrid.getGroupTree();
            if (tree == null) {
                return;
            }
            //tree.getchildren is the same as getfolders, since the nodes under the root ARE the group nodes :)
            for (TreeNode groupNode : tree.getChildren(tree.getRoot())) {
                setGroupHeader(tree, groupNode, groupSummaryNameColumn);
            }
            groupedGrid.markForRedraw();
        }
    
        protected void setGroupHeader(Tree tree, TreeNode groupNode, String groupSummaryNameColumn) {
            String sum = findGroupSummaryField(tree, groupNode, groupSummaryNameColumn);
    
            if (sum != null) {
                groupNode.setAttribute("groupValue", groupNode.getAttribute("groupValue") + ": " + formatter.format(sum, groupNode, 1, 1) + " " + unitName);
            } else {
                groupNode.setAttribute("groupValue", groupNode.getAttribute("groupValue"));
            }
        }
    
     //THIS is where i locate the summary node from the children, and get the correct sum field that i am interested in
        protected String findGroupSummaryField(Tree tree, TreeNode parent, String attribute) {
            String extref = null;
            for (TreeNode node : tree.getChildren(parent)) {
                System.out.println(node.getTitle() + ", class: "+node.getClass().toString());
                if (extref == null) {
                    extref = node.getAttribute("extref");
                }
                if (node.getIsGroupSummary()) {
                    return node.getAttribute(attribute);
                }
            }
    
            return null;
        }

    #2
    Your existing code already traverses the groupTree, with no context other than the groupValue found on the groundNode.

    What is different about being called as a groupTitleRenderer? You have the groupNode passed to you, so it looks like you have the same context.

    Comment


      #3
      Well, in order to put one of the summarized values, i need the "summary" treenode, which in the tree is one of the children of the group node (see in my code where i traverse the children of the groupnode until i find the "isGroupSummary"-node. However in the GroupTitleRenderer, when i traverse the children of the "GroupNode", i only get my own rows that belong to the group, there is no "groupsummary"-row in the children, so i cannot get at the summary numbers i'm after.

      EDIT: But hey, never mind, i'll just keep my code :)

      Comment

      Working...
      X