PDA

View Full Version : Strange Double Grid Group Titles



chalu
14 Mar 2012, 6:16 AM
Hello folks, I am having my grouped grid show up with double group titles / headers. That is, each group title shows up twice and I can't figure out why. I am using a custom GroupingView class which simply uses a MAP to store the GroupColumnData for each "group" from within the last loop inside the doRender() method.



public class GroupingView extends com.extjs.gxt.ui.client.widget.grid.GroupingView {

// These guys were declared private in the supperclass
// but we need them in our overriden onRender() method
// so we just copied them here.
private boolean showGroupName;
private Map<String, Boolean> state = new FastMap<Boolean>();

// This is why we made this class in the first place.
// Keep our GroupColumnData objects for public use.
protected Map<String, GroupColumnData> groupStore;

public GroupingView() {
super();

groupStore = new LinkedHashMap<String, GroupColumnData>();
}

@Override
protected String doRender(List<ColumnData> cs, List<ModelData> rows,
int startRow, int colCount, boolean stripe) {
if (rows.size() < 1) {
return "";
}

String groupField = getGroupField();
int colIndex = cm.findColumnIndex(groupField);

enableGrouping = groupField != null;

if (!enableGrouping || isUpdating) {
return super.doRender(cs, rows, startRow, colCount, stripe);
}

String gstyle = "width:" + getTotalWidth() + "px;";
String gidPrefix = grid.getId();

ColumnConfig cfg = cm.getColumn(colIndex);

String prefix = showGroupName ? cfg.getHeader() + ": " : "";

GroupColumnData curGroup = null;
String gid = null;

List<GroupColumnData> groups = new ArrayList<GroupColumnData>();

for (int j = 0; j < rows.size(); j++) {
ModelData model = (ModelData) rows.get(j);

int rowIndex = (j + startRow);

// the value for the group field
Object gvalue = model.get(groupField);

// the rendered group value
String g = getGroup(gvalue, model, rowIndex, colIndex, ds);

if (curGroup == null || !curGroup.group.equals(g)) {
gid = getGroupId(gidPrefix, groupField, g);

boolean isCollapsed = state.get(gid) != null ? !state.get(gid)
: isStartCollapsed();
String gcls = isCollapsed ? "x-grid-group-collapsed" : "";

curGroup = new GroupColumnData();
curGroup.group = g;
curGroup.field = groupField;
curGroup.gvalue = gvalue;
curGroup.text = prefix + g;
curGroup.groupId = gid;
curGroup.startRow = rowIndex;
curGroup.style = gstyle;
curGroup.css = gcls;
curGroup.models.add(model);
groups.add(curGroup);

} else {
curGroup.models.add(model);
}
// model.set("_groupId", gid);

}

for (GroupColumnData group : groups) {
if (getGroupRenderer() != null) {
String g = getGroupRenderer().render(group);
if (g == null || g.equals("")) {
g = "&nbsp;";
}
group.group = g;
}
}

StringBuilder buf = new StringBuilder();

for (int i = 0, len = groups.size(); i < len; i++) {
GroupColumnData g = groups.get(i);

// this is where we add it
// the GroupColumnData for a group
// is placed in the map, using the
// group's id as key.
groupStore.put(g.groupId, g);

doGroupStart(buf, g, cs, colCount);
buf.append(super.doRender(cs, g.models, g.startRow, colCount,
stripe));
doGroupEnd(buf, g, cs, colCount);
}

return buf.toString();
}

public Map<String, GroupColumnData> getGroupStore() {
return groupStore;
}


This derived class just makes use of two "copied" private variables. and introduces a Map<String, GroupColumnData> groupStore so that the GroupColumnData objects representing the groups can gotten from outside.

This is supposed to be simple, but for reasons I have not been able to find out, it causes the group titles to duplicate. See attached screenshot, please I need your help. Thanks in advance.
32728