AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=1355&pId=-1
Creating and Designing Report using iReport - Part 2
page
by Anuva Das
Feedback
Average Rating: 
Views (Total / Last 10 Days): 56066/ 40

Introduction

This article is related to my previous article entitled "Creating And Designing Report using iReport - Part 1." This article explains advanced features such as subreport and crosstab of ireport and how to generate reports using them.

Subreport

A Subreport (a report within a report) is an important feature of report generating tool. In some situations you might need more than one query to retrieve data from database, and then you can use the subreport feature of iReport. A report can contain more than one subreport. Each report, including a parent report and a child report, has its own SQL query to retrieve data from database.

Suppose you want to display the sales order details of each salesman. For that, first you have to create the parent report that displays all the salesmen. Now create the subreport that displays the order details of each salesman. To create subreport select “Edit-> Insert Element    ->  subreport” or click the “subreport” icons. It will open the following dialog.

Figure 1

Click the next button and write the query in the “SQL query” text box.

Figure 2

Now click the next button. Select the required fields to display in your subreport.

Figure 3

Continue the subreport generating process by clicking the next button. It will open the following dialog, having different layouts to display the subreport. Choose a suitable template from the above dialog for your report and click the next button.

Figure 4

In the following “Subreport expression” dialog, if you choose the first option then you have to specify the path of your subreport’s jasper file in the “SUBREPORT_DIR” parameter.

Figure 5

Now click the finish button to get a subreport table that displays your subreport.

Create a parameter (for example: salesmanId) in the subreport. Now open the properties by right clicking on the subreport icons. Click the subreport(Other) tab as shown in the following dialog.

Figure 6

To add a parameter click the Add button and fill up the parameter name and default value expression field in the “Add/modify parameter” dialog as shown in the following dialog.

Figure 7

Now change the subreport query to display the order details of each salesman by passing their “salesId” as a parameter to the subreport. The following query is used for this.

Listing 1

Select * from order_details where salesId = $P{salesmanId}

When it is run it generates a report like this:

Figure 8

Crosstab

Sometimes we need to display a report in cross tabular format. Crosstab is nothing but a special type of table component in which both the rows and the columns are dynamic. They are used to summarize and visualize data in a compact form with multiple levels of grouping for both columns and rows.

Suppose you want to create a report that shows Revenues for computer sales of different years.

For that, first add the query in your report as shown below.

Figure 9

Now use the following steps to create a crosstab report.

Steps 1

Add crosstab from the menubar in the summary section. It will show the following dialog box. Select “Available Subdataset” or you can create a new Subdataset. Now click the next button.

Figure 10

Steps 2

It will show the following dialog box. Select row group 1 and row group 2 and click the next button in the following dialog box.

Figure 11

Steps 3

It will show the following dialog box. Select column group 1 and column group2 and click the next button in the following dialog box.

Figure 12

Steps 4

It will now show the following dialog box. Select detail field and function to show the result. Now click the next button.

Figure 14

Steps 5

It will show the following dialog box. You can make the “Add row group totals” and the “Add column group totals” check boxes checked to display the total of each row and each column respectively in your report.

Figure 15

Steps 6

Now click the “finish” button and run the report. It generates a report as shown below.

Figure 16

Crosstab must be placed in the summary section.

Conclusion

This article uses a simple way to create a subreport and cross tabular report. I hope this will help readers create their own report with iReport.

By Anuva Das

Mindfire Solutions

 


Product Spotlight
Product Spotlight 

©Copyright 1998-2021 ASPAlliance.com  |  Page Processed at 2021-02-27 10:47:54 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search