Multiple Groups in jasper reports

Ujjwala picture Ujjwala · Jul 5, 2011 · Viewed 12.5k times · Source

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?

Answer

Tom picture Tom · Jun 15, 2012

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.