Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Optional Grouping
Optional Grouping [message #1840829] Mon, 26 April 2021 09:38 Go to next message
Bob D is currently offline Bob DFriend
Messages: 2
Registered: November 2017
Junior Member
I'm trying to create a report where the grouping in the report is optional. If a checkbox is ticked, then a grouping should be applied on the table. And if the checkbox is unticked, then there should be no grouping applied, and the data should be presented as a flat table.

Here are a couple of approaches that I've attempted:

1) Set a 'Group On' expression which is based on the report parameter. When the report parameter is true, then this Group On expression will return the field to group on, e.g.

if(params["groupByCountry"].value){
 row["COUNTRY"];
}


This solution kinda works, but when I export to Excel there are a few niggly issues.

Firstly, the group header is displayed even when the grouping is disabled. A workaround for this issue is to also make the display of the group header to be conditional on the group parameter.

Secondly, the excel document has an outline which has a collapsable grouping even when the checkbox is unticked. Ideally it would be good to not display this outline when grouping is disabled.

Please see the attached file (ParameterizedGrouping1.rptdesign) for an example of this approach.

2) Use javascript to manually create the group

The code looks something like the following:

importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.java.io);

if (params["groupByCountry"].value) {
 var reportDesignHandle = reportContext.getDesignHandle();
 var table = reportDesignHandle.findElement("Table");
 var elementFactory = reportDesignHandle.getElementFactory();
 var group = elementFactory.newTableGroup();
 group.setName("COUNTRY");
 group.setKeyExpr( "row[\"COUNTRY\"]" );
 group.setSortDirection("asc");
 var row = elementFactory.newTableRow(1);
 var cellHandle = row.getCells().get(0);
 var data = elementFactory.newDataItem(null);
 data.setResultSetColumn("COUNTRY");
 cellHandle.getContent().add(data);
 group.getHeader().add(row);
 table.getGroups().add(group, 1);
}


An example of this is provided in the attached file (ParameterizedGrouping2.rptdesign).

The benefit of the first approach is that it's simple and can be done in the report designer, without much custom code. However, it has a few niggly issues.

The benefit of the second approach is that it overcomes some of the niggly issues, but the JS code is more cumbersome to write.

Are there any other approaches which could be used other than those described above?
Re: Optional Grouping [message #1840859 is a reply to message #1840829] Tue, 27 April 2021 05:58 Go to previous message
Colin Sutton is currently offline Colin SuttonFriend
Messages: 121
Registered: July 2009
Senior Member
A simple solution would be to create two tables, simple and grouped, and hide one of them according to the parameter.
Previous Topic:Invalid version number: Version number may be negative or greater than 255
Next Topic:Testing BIRT report
Goto Forum:
  


Current Time: Tue Apr 16 04:29:57 GMT 2024

Powered by FUDForum. Page generated in 1.20001 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top