Getting Started with the Table Component
為什么80%的碼農都做不了架構師?>>> ??
Home ? Wiki ? Getting Started with the Table ComponentGetting Started with the Table Component
Table of Contents [hide]- Creating Your First Report using the Table Component
- Step 1: Create a datasource/database connection
- Step 2: Create a New Report
- Step 3: Add a dataset to populate the table component
- Step 4: Add the Table Component to the Report
- Step 5: Deploy the report to JasperReports Server
- Using the First Set of Interactive Features
- Sorting
- Filtering
- An Example
- Creating Your First Report using 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 make changes that we should be able to do on our own.
With the table component for JasperReports combined with the JasperReports Server platform (Community and Commercial Editions), we have introduced the beginning of 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 this understanding of the element relationships, we can now introduce additional 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, more informed decisions.
Creating Your First Report using the Table Component
Let's take a brief look at how to implement a report using the Table Component to generate a simple tabular representation of data. The following are the basic steps we will take:
Step 1: Create a datasource/database connection
Our first step will be establish a database connection within iReport that we can use to provide data for our report. To make things simple, we will use the foodmart data that is included as sample data with JasperReports Server.
?
Step 2: Create a New Report
Next, let's create a new report in iReport. Note: Because the table component uses it's own dataset, I will set up my main report query to have a dummy query of: Select 1 as dummy_field You now have a simple report showing various bands. For the purposes of this example, we will only use the Title and Summary bands.
Step 3: Add a dataset to populate the table component
The table component does not get its data from the main report query. Rather, it requires 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 independently from the table.
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 to add the table component to the report. 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 and typing the text you want. 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 available from margin to margin.
Now that we have everything in the report set up, we can confirm that it works as expected by running it within iReport.
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 the report that we created and deploy it to JasperReports Server. 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 developed our report for.
Now you are ready to login to your JasperReports Server instance and run your report.
Using the First Set of Interactive Features
Once you login to JasperReports Server and run your report that uses the table 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 then by the second.
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 the type of data you are filtering.
Adding a filter to a column will result in the data being filtered and a filter indicator appearing in the column header.
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. We can now filter and sort our way to the answer:
- Add a filter on the gender column to "Equals" F
- Add a filter on the # of Children to "Greater Than" 4
- Add a filter on the Country to "Equals" Canada
- Add a filter on the Home Owner column to "Equals" Y
- Sort on the name column
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. Want the report source for this example? Download it here.
?轉載于:https://my.oschina.net/liango/blog/87479
總結
以上是生活随笔為你收集整理的Getting Started with the Table Component的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ASP.NET MVC3 异步刷新
- 下一篇: poj1484