Академический Документы
Профессиональный Документы
Культура Документы
Table Component
JasperReports Interactivity: The Table Component
https://www.jaspersoft.com/blog-entry/jasperreports-interactivity-the-table-component
We have all had experience looking at static reports and wishing we could filter, re-sort,
or even highlight particular data points as we analyze what the data means. Many times,
this has involved exporting the data to another tool, such as Excel, and doing additional
analysis there – or worse, asking the report developer to create yet another report to
With the table component for JasperReports combined with the JasperReports Server
what will be some very exciting interactivity features for the consumers of your reports.
The table component adds additional structural elements so that JasperReports not only
understands the layout of the individual elements that make up the columns and rows
within your tables, but also recognizes the relationship between these elements. With
intelligence within the final report output that will make the reports more interactive and
allow you to conduct the additional analysis of information, that you may not have
anticipated prior to seeing the data, directly through the report output to make faster,
generate a simple tabular representation of data. The following are the basic steps we
will take:
1. Set up a data source connection within iReport from where we will pull data for
our report
2. Create a new report within iReport, using the report wizard and remove the report
bands that we won’t need for our report
3. Set up a new data set for the table component to use
4. Add and format the table component to display the data we are interested in
5. Deploy the report to the JasperReports Server repository
provide data for our report. To make things simple, we will use the foodmart data that is
1. Open iReport
2. Click on the Report Datasources icon to add a new datasource
3. Click “New”
4. Select “Database JDBC connection” as the datasource type, and click “Next”
5. Fill in a name and the database connectivity information to the foodmart data
Note: Because the table component uses it’s own dataset, I will set up my main report
You now have a simple report showing various bands. For the purposes of this example,
a separate data set to populate from. This is convenient in cases where you want to have
a chart as well as a table as the main report query can be used to populate the chart
1. In the repository inspector pane within iReport, right click on the top level of the
report tree representing the Report itself and select “Add Dataset”
2. Name your dataset – for this example, I will name it “Table Dataset”
3. Select to create the dataset from a connection or datasource and click “Next”
4. Select the data source that we created in step 1 and enter the following query
and click “OK”:
6. country AS customer_country,
7. gender AS customer_gender,
8. total_children AS customer_total_children,
9. occupation AS customer_occupation,
FROM customer
Step 4: Add the Table Component to the Report
Now that we have a report with a dataset defined for our table component, we are ready
Once you have set and accepted the formatting, the table will open with the fields
populated in the table as well as the field names as the heading in the column header.
You can change the heading text to any text that you wish by double clicking on the cell
Lastly, we need to make sure that the table component is sized in our main report so that
it will fit properly. Each of the columns in the table is automatically sized to 90 pixels,
giving us a total of 630 pixels across. Looking at the main report, there is 752 pixels
1. Within iReport, drag the Table from the Palette into the Summary Band
2. When the Table Wizard opens, select the Dataset we defined in Step 3 as the
dataset from which the table should be created and click “Next”
3. Select all of the fields and move them to the right column in the field selector and
click “Next” (Note that the order here is the order that the fields will appear in your
table.)
4. Select to use the same connection used to fill the master report and click “Next”
5. Now set the formatting for your table:
1. Select the color scheme you want to use within your table
2. Check the box to use an alternated detail row background
3. Set the border style based on your preference
4. Select the headers and footers you want to include in the report – for the
purposes of this example, I will choose to only include the column header
5. Click “Finish”
6. Right click on the table component in the main report and select “Size > Adapt to
Parent” in order to automatically set the table component available size to the same
as the Summary band.
Now that we have everything in the report set up, we can confirm that it works as
1. Make sure that the datasource we set up in Step 1 is selected as the current
Datasource in iReport.
2. Now click “Preview”
The report should run, pulling data from the datasource and presenting the first page as
expected.
Step 5: Deploy the report to JasperReports Server
We will assume that you have already set up a connection to your installation of the
JasperReports Server. Using the Repository Navigator within iReport, we will now take
In our case, since we are using the sample data that came with the JasperReports
Server, a data source is already defined that points at the Foodmart data that we
1. Change from the preview back to the Designer mode within iReport
2. Navigate in the Repository Navigator to the folder where you want to deploy your
report
3. Right click on the folder and select “Add > JasperServer Report”
4. Give the report a unique ID, a descriptive name, and a Descriptive description and
click “Next”
5. Select to use a “Locally Defined” JRXML file and click “Get source from current
opened report” an then click “Next”
6. Click to select a Data Source from the repository and click “Browse”
7. Browse to “analysis/datasources” and select the “FoodMartDataSource” and click
“Open Resource”
8. Finally, click “Finish”
Now you are ready to login to your JasperReports Server instance and run your report.
component, you will be able to access interactive features such as sorting and filtering.
Sorting
To sort the data, click on the column header for the field you want to sort by:
Clicking once will sort ascending and present an indicator in the column header
that the data is sorted
Clicking a second time will change the sort to descending and change the
direction of the sort indicator
Clicking a third time will eliminate the sorting and remove the sort indicator
Sorting a second column will result in the data first being sorted by the first column and
Filtering
To filter the data, right click on the column header for the field you want to filter based
on. There are various filter options such as equals, between, greater than, etc. based on
Adding a filter to a column will result in the data being filtered and a filter indicator
To remove a filter, simply right click on the column again and click “Clear” on the filter.
An Example:
Taking the sample report we created, we can use filtering and sorting to identify
answers to questions that we may not have thought to ask when we were designing the
report initially.
For example, let’s say that we wanted to know which female customers were from
Canada, had more than 4 children and owned a home. We want this list sorted by name.
Using these simple sorting and filtering features, we now have a 2 page list of customers
that meet the criteria that we were looking for from our original list of over 380 pages.
We can now export the resulting report in the format we wish to share it in.
You can see the value of the table component and the interactivity it introduces when
combined with the server platform. Over time, we will expand on the capabilities and the
value will only increase. I hope this post will help you to make use of the table
component wherever you can to put even more power in the hands of your users.
Get involved with our community and provide you input on the interactivity features by