This recipe shows how you can build a simple one-page TOC for your report.
Refer to the installPostgreSQL.txt
file included in the source code download of this chapter to install and run PostgreSQL, which should be up and running before you proceed. The source code of this chapter also includes a file named copySampleDataIntoPGS.txt
, which helps you create a database named jasperdb6
and copy sample data for this recipe into the database.
SimpleTOCReport.jrxml
file from the Task2
folder of the source code of this chapter. The Designer tab of iReport shows a report containing data in Title, Column Header, Customer Group Header 1, Product Group Header 1, Detail 1, and Product Group Footer 1 sections, as shown in the following screenshot: FirstRecordOfANewGroup
. Now the name of the variable1 variable will change to FirstRecordOfANewGroup
. java.lang.Integer
. Count.
Group.
Customer
. FirstRecordOfANewGroup
variable in the second column. A new expression $V{FirstRecordOfANewGroup}
will appear in the Variable Expression window, as shown in the next screenshot. Press the OK button. TOC
. Now the name of the variable1 variable will change to TOC
. java.lang.String
. Report
, as shown in the following screenshot: ($V{FirstRecordOfANewGroup}==0) ? ($V{TOC}+$F{CustomerName}+" ............................................ " + $V{PAGE_NUMBER}+"<br/>") :$V{TOC}
in the expression editor window, as shown in the next screenshot. Press the OK button. new java.lang.String()
as its value. Now the properties of the TOC variable are all set. SimpleTOCReport.jrxml
file. You have to close and re-open your .jrxml
file every time you play with the Initial Value Expression property of a variable. This is due to a bug in iReport version 3.6.0 200
. $V{TOC}
text field in the Title section. Its properties will appear in the Properties window below the Palette. Find the Width property and set its value as 300
. Similarly, set 100
as the value of its Height property. html
as its value from the drop-down list beside it. $V{TOC}
text field in the Title section. Its properties will appear in the Properties window below the Palette. Find the Evaluation Time property and select Report
as its value from the drop-down list beside it. $V{TOC}
text field. You will see a prompt to choose between a Page break or Column break, as shown in the next screenshot. Press OK to accept the Page break option, selected by default.You have used a two-variable trick to build a one-page TOC for your customer invoices report. The two variables are FirstRecordOfANewGroup
(which you named in step 5) and TOC
(which you named in step 14). These two variables together build the TOC, as explained below.
The FirstRecordOfANewGroup
variable keeps count of records for each customer. This variable resets at the start of records for each customer, because you set its Reset type property to Group
and its Reset group property to Customer
in steps 8 and 9, respectively. Moreover, the FirstRecordOfANewGroup
variable is incremented by 1 for each record due to count
being the value of the Calculation property you set in step 7. Therefore, the value of this variable is zero (0) at the start of each customer and increments as JasperReports processes records of that customer.
Now look at the ($V{FirstRecordOfANewGroup}==0 ) ? ($V{TOC} + $F{CustomerName} + " ............................................ " + $V{PAGE_NUMBER}+"<br/>") :$V{TOC}
expression for the TOC variable that you authored in step 18. This is a complex expression which does the following:
TOC
variable concatenates the customer name and current page number into its current value. TOC
variable simply holds its previous contents without any change.This way, the TOC
variable builds the complete TOC of the report. Note that you dropped the TOC
variable as a field into the Title section in step 24 and set the Evaluation Time property of the $V{TOC}
field to Report
. This means that the value of the TOC
variable will be copied to the $V{TOC}
field only at the end of the report processing, so that the complete TOC is displayed.
Similarly, in step 26 you selected html
as the value of the Markup property of the $V{TOC}
field because you used a<br/>
HTML tag in the expression for the TOC
variable earlier in step 18.
3.145.178.151