iReports Grouping Bug - Multiple Occurrences?
Asked Answered
E

2

6

I'm am getting irritated with iReports. Problem is that I have a data set returning data for multiple customers and I want to use the "Group Expression" against the customer ID and have the report lay out the Detail Tabs per customer.

I'm finding that, seeming randomly, where there is more that one data row for a customer iReports will generate two or more groupings (Sometimes it does what I expect and group all the customer data together), the field IDing the customer is the same and doesn't change.

Has anyone seen this before? To be honest I can't believe it is actually a bug, but something I've missed. Just much searching as yet to find a suitable result.

Erythroblastosis answered 13/10, 2011 at 16:46 Comment(1)
Did you sort data by customer id (the field on which you group by)?Gentoo
G
8

I think this is a data sorting problem.
The quote from iReport Ultimate Guide:

JasperReports groups records by evaluating the group expression. Every time the expression's value changes, a new group instance is created. The engine does not perform any record sorting (if not explicitly requested), so when we define groups we should always take care of the records sorting. That is, if we want to group a set of addresses by country, the records we select for the report should already by ordered by country. It is simple to sort data when using an SQL query by using the ORDER BY clause. When this is not possible (that is, when obtaining the records from an XML document), we can request that JasperReports sort the data for us. This can be done using the sort options available in the query window


You can sort data in these ways:

  • in case using of Database jdbc connection datasource type you can add ORDER BY customerId clause to the report's query, where customerId - column name of field with customer id
  • in case using of File csv connection or something like this you can organize data sorting by adding sortField property for field to the report's template (jrxml file):
<jasperReport ...>
    ...
    <field name="customerId" class="java.lang.String"/>
    <sortField name="customerId"/>
Gentoo answered 14/10, 2011 at 5:45 Comment(0)
A
3
  1. SQL Statement has ORDER BY?
  2. iReport group is grouped by customer_id?
Airdry answered 8/11, 2011 at 9:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.