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:
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.
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)
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; }
Comment