I managed to have both the title group header and the summaryGroupRow visibile when the group is collapse.
Of course, it is not the best solution at all, but it is the best I could get to.
First, I set the grid to have the summary visible in the header and not to build the extra column for the group title (I need all the space for the meaningful data):
Code:
grid.setShowGroupSummary(true); grid.setShowGroupSummaryInHeader(true); grid.setShowGroupTitleColumn(false); //no extra column!!
Code:
grid.addGroupByHandler(new GroupByHandler() {
@Override
public void onGroupBy(GroupByEvent event) {
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
addTitleRow();
}
});
}
});
//Need to memoriez the added nodes
Set<TreeNode> fakeNodes = new HashSet<TreeNode>();
protected void addTitleRow() {
if (grid.getGroupTree() == null) {
return;
}
//Need to remove the added row, or they may be duplicated
for (TreeNode fake : fakeNodes) {
grid.getGroupTree().remove(fake);
}
fakeNodes.clear();
TreeNode parent = grid.getGroupTree().getRoot();
TreeNode[] originalFolder = grid.getGroupTree().getDescendantFolders();
int pos = 0;
for (TreeNode nt : originalFolder) {
TreeNode head = new TreeNode();
Object title = nt.getAttributeAsObject("groupValue");
head.setSingleCellValue(nt.getAttributeAsObject("groupValue"););
head.setAttribute("groupFakeTitleRow", Boolean.TRUE);
head.setCustomStyle("groupFakeTitleRow");
head.setCanExpand(false);
head.setIsGroupSummary(true);
head.setIsFolder(true);
head.setEnabled(false); //It cannot be clicked nor selected
grid.getGroupTree().add(head, parent, pos);
fakeNodes.add(head);
pos += 2;
}
}
Code:
grid.addSortChangedHandler(new SortChangedHandler() {
@Override
public void onSortChanged(SortEvent event) {
final String[] fields = grid.getGroupByFields();
grid.groupBy();
fakeNodes.clear();
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
grid.groupBy(fields);
}
});
}
});
At this point, I wonder if there is a way I can act directly on the piece of code that build the "summaryGroupRow", from the beggining, but I have no idea on how this can be achived.
I attach a screenshot of the resulting grid.
Thank you,
Barbara
Leave a comment: