Multiple Groups in jasper reports
Asked Answered
C

4

6

I want to create multiple groups in ireport, and the data should display in a group-wise manner.For Eg: First the Group1 data should be printed completely, then,


Group1:


Module Data After this i want to print the Group2 data completely

Group2:


Category data

I am using the Result Set datasource.

Can Someone help me in this?

Childbearing answered 5/7, 2011 at 10:23 Comment(0)
B
4

Jasper reports will work exactly in this manner as long as your query results are ordered properly.

For example, let's say you are grouping by a field called "MY_GROUP" and it has values "GROUP A" and "GROUP B". In your report you will create a group for field "MY_GROUP". In your query, make sure you have MY_GROUP as the first field in your ORDER BY clause. You can also accomplish this in iReports by adding the "MY_GROUP" field as your the first field in the Sort Options section of the Report query.

Now that you have added your group and are ordering properly your results will come out like this:

Header - GROUP A Detail - GROUP A Footer - GROUP A Header - GROUP B Detail - GROUP B Footer - GROUP B

Exactly as you wish. My guess is that you were not properly ordering your query results. This could result in having multiple groupings for GROUP A, GROUP B, etc. all interspersed.

Bort answered 15/6, 2012 at 18:26 Comment(0)
R
3

It's exactly as Tom said. Jasper Reports Groups do not order the data retrieved from the query, they just take it in the order it comes.

In order to display the information in a group-wise manner, you have to add an ORDER BY to the query so the rows the report receives are already ordered.

Radiculitis answered 23/7, 2014 at 20:15 Comment(0)
S
2

If groups in iReport don't keep all the data together, use subreports. When Jasper gets to a subreport, it runs the whole subreport and puts the whole thing into the report. You could have something like:

Subreport 1 - Group 1 Group 1 first record Group 1 second record Group 1 third record ... Group 1 last record Subreport 2 - Group 2 Group 2 first record Group 2 second record Group 2 third record ... Group 2 third record

Salado answered 5/7, 2011 at 17:18 Comment(0)
B
0

So there is an issue that happens when you use multiple group headers. The first header behaves like expected ordered by Column Value A only on unique values. The 2nd header using Column Value B will print on every row despite being non-unique values.

  1. In theory you should be able to use ORDER BY:
ORDER BY ValueA, ValueB

to properly display the report assuming you are using sql, plsql, etc... However, in my case that did not happen, though for others it seems to work.

  1. Use subreports to attach the minor differences via unique reports. You create a root report with empty details. Then you create Unique reports to serve as sub reprots. Finally, you use the subreport element to link the values into the root report. Though that is a good bit of work and may cause repeat code.
  2. A hacky way I used was: A mixture of "Print When Expressions" with logical boolean expressions with 2 group headers and a column header. Boolean Expressions:
$F{QUERY}.equals(Query1) && ($P{P_Typequery}.equalsIgnoreCase("QueryA") && $P{P_parameter} == null) 

and

$F{QUERY}.equals(Query1) && ($P{P_Typequery}.equalsIgnoreCase("P_QueryA") && $P{P_parameter} != null) 

with two group headers and a column header. The column header will not repeat for every row so you assign one of the booleans expressions to it's "print when" so it does not always print. The first group header will not repeat for every row and works. The 2nd group header is used for the times you DO want it to repeat for every unique value since it always prints for every row, and you use the other boolean on it's "print when". Hope it helps

Brendis answered 22/4, 2020 at 20:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.