BIRT Grouping with Aggregation [message #1744328] |
Sun, 25 September 2016 16:21 |
debajit saikia Messages: 1 Registered: September 2016 |
Junior Member |
|
|
I would like to generate a report dynamically that groups all the rows based on particular column and want to add a row after each group that sums up
all the rows of that particular group. My code is able to divide the rows into groups properly but facing into adding the row after each group that shows aggregation of that particular group. Row after each group showing the same aggregate value for group.
ElementFactory designFactory = designHandle.getElementFactory();
TableHandle table = designFactory.newTableItem("table", cols.size());
table.setDataSet(designHandle.findDataSet(dataSetName));
TableGroupHandle group = designFactory.newTableGroup();
group.setName("group_colGroup");
group.setKeyExpr("dataSetRow[\"" + cols.get(0).getObjectField() + "\"]");
group.setInterval("none");
group.setSortDirection(DesignChoiceConstants.SORT_DIRECTION_ASC);
group.setRepeatHeader(true);
PropertyHandle computedSet = table.getColumnBindings();
org.eclipse.birt.report.model.api.elements.structures.ComputedColumn cs1 = null;
for (int i = 0; i < cols.size(); i++) {
cs1 = StructureFactory.createComputedColumn();
cs1.setName(cols.get(i).getObjectField());
cs1.setExpression("dataSetRow[\"" + cols.get(i).getObjectField() + "\"]");
computedSet.addItem(cs1);
}
// table header
RowHandle tableheader = (RowHandle) table.getHeader().get(0);
tableheader.setProperty("textAlign", "center");
for (int i = 0; i < cols.size(); i++) {
LabelHandle label1 = designFactory.newLabel(cols.get(i).getObjectField());
label1.setText(cols.get(i).getObjectName());
CellHandle cell = (CellHandle) tableheader.getCells().get(i);
cell.getContent().add(label1);
}
// table detail
RowHandle tabledetail = (RowHandle) table.getDetail().get(0);
for (int i = 0; i < cols.size(); i++) {
CellHandle cell = (CellHandle) tabledetail.getCells().get(i);
DataItemHandle data = designFactory.newDataItem("data_" + cols.get(i).getObjectField());
data.setResultSetColumn(cols.get(i).getObjectField());
cell.getContent().add(data);
}
RowHandle groupFooter = designFactory.newTableRow(cols.size());
PropertyHandle computedSet1 = table.getColumnBindings();
org.eclipse.birt.report.model.api.elements.structures.ComputedColumn cs2 = null;
for (int i = 0; i < cols.size(); i++) {
MetaData metaData = cols.get(i);
cs2 = StructureFactory.createComputedColumn();
cs2.setName("Group-" + cols.get(i).getObjectField());
cs2.setExpression("dataSetRow[\"" + cols.get(i).getObjectField() + "\"]");
if (metaData.isIsAggregate()) {
cs2.setAggregateFunction(metaData.getAggregateFunction());
}
computedSet1.addItem(cs2);
CellHandle fcell = (CellHandle) groupFooter.getCells().get(i);
DataItemHandle data = designFactory.newDataItem(null);
if (metaData.isIsAggregate()) {
data.setResultSetColumn("Group-" + cols.get(i).getObjectField());
}
data.setName("GroupValue-" + i);
fcell.getContent().add(data);
}
group.getFooter().add(groupFooter);
table.getGroups().add(group);
|
|
|
Powered by
FUDForum. Page generated in 0.01603 seconds