The subreport element includes a subreport inside a report. The subreport is represented by an external Jasper file. It can use the same database connection as the parent report or a data source specified in the subreport properties. Subreports are useful for charts that don't need all the data in the main report.
The following briefly describes the characteristics of subreports:
This expression returns a subreport expression class object at run time. According to the return type, the expression is evaluated in order to recover a Jasper object to be used to produce the subreport. In case the expression class is set to java.lang.String, JasperReports looks for a file following the same approach explained for the Image Expression of the Image element. | |
This is the class type of the expression; there are several options, each for a different way to load the JasperReport object used for the subreport. | |
This specifies whether the subreport's report object is kept in memory or reloaded each time it's used. It is common for a subreport element to be printed more than once (or once for each record in the main dataset). The cache works only if the subreport expression type is String, because that string is used as key for the cache. | |
This identifies the expression returned at run time when a JDBC connection or a JRDataSource used to fill in the subreport. Alternatively you can choose not to pass any data. This option is useful at times. However, a subreport, like any report, returns an empty document if data are not provided. So in this case, the subreport should have the document property When No Data Type set to something like All Sections, No Detail. | |
This optional expression can be used to produce a java.util.Mapobject at run time. The map must contain a set of coupled names/objects that are passed to the subreport to set a value for its parameters. | |
This table allows you to define some coupled names/expressions that are useful to dynamically set a value for the subreport parameters using calculated expressions. | |
This table allows you to define how to store values in local variables calculated or processed in the subreport (such as totals and record count). |
1. | Drag the Subreport element from the Palette to the area of your report where you want to use it. |
The Subreport wizard provides three options:
• | Create a new report: Use this option when you need to use data or a query not available in an existing report. |
• | Select an existing report: Use this option when you want to choose a report from the repository. |
• | Just create the subreport element: Use this option to create a placeholder to be used later. |
Subreport Wizard |
2. | Select Create a new report and click Next. The New Report Wizard > Report Templates window appears. |
3. | Select a template for your subreport. For this example, select one of the blank templates. Click Next. The New Report Wizard > Report file window opens. |
4. | Select a location for your subreport, and name it. Click Next. The Data Source window opens. |
Data Source and Query |
5. | Choose to use the same data adapter as the main report, or a different data adapter. |
For this example, choose the same adapter (Sugar CRM). Enter the following SQL query:
select count (*), shipcity from orders group by shipcity
Add all the fields to the list on the right. Click Next.
6. | Click Next to skip the Group By step. The Subreport > Connection window opens. |
Subreport > Connection Window |
7. | Choose to connect either to the same database as the main report or to a different database. For this example, click Use same connection used to fill the master report. |
8. | Click Next. The Subreport Parameters window opens. |
Subreport Parameters Window |
9. | For this example, skip this window and click Finish. A new report opens containing all bands. |
10. | Delete all bands but the Title or Summary band to eliminate extra white space in your report. |
You now have a location into which to place your table, chart, or other element attached to the new subreport.
Recommended Comments
There are no comments to display.