Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the same datasource twice in JasperReports/iReport

I'm trying to work out how best to do reports with a chart then a table representing the same dataset. I need to overcome the positioning of the summary is at the bottom, so intend to use subreports and table-subreports. I am experimenting with two tables and a chart in one detail band.

If I set the datasourceexpression for to $P{REPORT_DATA_SOURCE} only the chart displays data (presumably the first subreport type item) and the tables are empty. Seems the data can be consumed only once?

If I use a Dataset to query the database it works however it executes the Query three times, once for each table/chart. That will be a massive overhead.

Obviously I am not doing this right but I cannot find any examples of using the same dataset more than once.

like image 527
KCD Avatar asked Sep 28 '11 01:09

KCD


People also ask

How do you pass main report data source to subreport JasperReports?

With a SQL connection, you can just pass a Connection Expression like $P{REPORT_CONNECTION} . Then the subreport has its own SQL query. In your case you want to pass the actual data. Depending on the details, it might be as simple as just defining a Parameter Map Expression like $P{REPORT_PARAMETERS_MAP} .

How do I use JRBeanCollectionDataSource?

In JRBeanCollectionDataSource(listjrbean) you should add collection of objects/beans. You need to verify bean should have getter and setter for empCode. For Ex class EmpClass { private String empCode; private String empName; public String getEmpCode() { return empCode; } public void setEmpCode(String empCode) { this.

What is $r in iReport?

$R{} is used for localization to replace value with those from the resource file. http://community.jaspersoft.com/questions/538008/rresource. 140055.


1 Answers

There is no simple answer so I have raised a feature request http://jasperforge.org/projects/jasperreports/tracker/view.php?id=5487

The suggested workarounds were:

  • implement a custom query executer to retrieve data from a cached datasource
  • generate a rewindable datasource based on the retrieved result set

Thanks to sanda aka shertage on the jasperforge forum for these suggestions.

like image 76
KCD Avatar answered Oct 23 '22 11:10

KCD