Skip to main content

Post 13: iReport: Inserting a heading for a group of records part 2

11. While your cursor is in query editor, press Enterkey to bring it in the next blank line  and type Order By 'CustomerName'. Click on OK button to dismiss the dialog.

12. Switch to the Preview tab. Navigate through all pages of your report, focusing on grouping of customer names. This time you will notice that there is only one group for each customer name (all the records for a single customer are displayed in a single group), as shown in the following screenshot:

13. Switch to the Designer tab. Select Customer Name static text from the Column Header section of your report and right-click on it. A pop-up menu will appear. Select Copy option from the pop-up menu, as shown.

14. Right-click anywhere on whites pace in the Customer Group Header 1 section of your report. A pop-up menu will appear. Select Paste option from the pop-up menu. A copy of customer name static text component will be generated in the section. Align the static text component to middle-left position in the Customer Group Header 1section, as shown in the following screenshot

 15. Select Customer Name text field component from Detail 1 section of your report and right-click on it. A pop-up menu will appear. Select the Copyoption from the pop-up menu.

16. Go to the Customer Group Header 1 section of your report. Right-click anywhere on the white space of the section. A pop-up menu will appear. Select the Paste option from the menu. A copy of the customer name text field component will be generated in the Customer Group Header 1 section. Align the text field component to the middle-left position in the Customer Group Header 1 section beside the static text  component of step 14, which you already have middle-left aligned in this section, as shown in the following screenshot:

17.Switch to the Switch to the Preview tab. Navigate through all the pages of your report. You will notice a group heading for each customer, as shown in the following screenshot:


How it works...
In this post you have learned how to use the grouping feature. This is a useful feature, as  it allows you to group records by dynamically inserting new sections in your report. Recall from step 5 that you chose CustomerName from the Group by the following report object drop-down list. When you did this, iReport created the group based on customer names. The result of this grouping is shown in the preview given in step 8, where you can see that wide  spaces are inserted whenever JasperReports detects that a customer name has changed. 

Another important point is that the grouping feature does not perform ordering of records. It only inserts a section (for example, whitespaces in the preview of step 8) when a group changes (that is, the customer name changes). Therefore, you have to provide records in order form for grouping to work properly. That's SQL's
job. Although SQL-related discussions are beyond the scope of this book, I have included an  Order byclause in step 11 to demonstrate how you will use SQL to order your records so that Jasper Reports can group them correctly.

Comments

Popular posts from this blog

Index: JSF

Java Server Faces Basics Post 1: JSF : Introduction to JSF  Post 2: JSF:  configuration files  Post 3: JSF: Installation Post 4: JSF: Your first JSF project   Standard JSF Tags Post 1: JSF: textbox example Post 2: JSF: password example Post 3: JSF: textarea example JSF 2 GraphicImage Example Post 4: JSF: GraphicImage Example Post 101 : JSF : The valueChangeListener Attribute Example

Index: iReport

iReport for Java ------------------------------------------------------------ Titles and Headers ------------------------------------------------------------ Post 1: iReport : Downloading, installing, and running JasperReports and iReport Post 2: iReport : Creating your first "Hello World" report   Post 3: iReport : Understanding iReport Elements Post 4: iReport : Creating and sizing the title for your report Post 5: iReport: Inserting a company logo in the title of your report  Post 6: iReport : Installation of PostgreSQL Post 7: iReport : Creating a report from relational data Post 8: iReport : Using dynamic titles that can change during report processing. Post 9: iReport : Adding a simple header to your report Post 10: iReport : Setting margins for your report and aligning the report header relative to report margins  ------------------------------------------------------------ Body and Footer ---------------------------------------------------------...