Multiple Groups in jasper reports

13,712

Solution 1

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.

Solution 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

Solution 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.

Share:
13,712

Related videos on Youtube

Ujjwala
Author by

Ujjwala

Updated on June 01, 2022

Comments

  • Ujjwala
    Ujjwala about 2 years

    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?