Getting Started with the Table Component

为什么80%的码农都做不了架构师?>>>   hot3.png

Getting 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

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:

  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

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.

  1. Open iReport Click on the Report Datasources icon to add a new datasource

 

  1. Click "New"
  2. Select "Database JDBC connection" as the datasource type, and click "Next"
  3. Fill in a name and the database connectivity information to the foodmart data within your database, and click "Save"

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.

  1. Click on "Step 2: create a new report"
  2. Select "Report"Â on the left side of the resulting window that opens and the "Blank Letter Landscape"Â template on the right and then click "Launch Report Wizard"
  3. Provide a name and file location to save your report and click "Next"
  4. Select the datasource that we created in step 1 and fill in a main report query and click "Next"
  5. Choose the fields for your report by moving them to the right side and Clicking "Next"
  6. Skip the grouping - click "Next"
  7. Click "Finish"
  8. Right click on each of the bands, except for the Title and Summary bands, and select "Delete Band"Â to remove the band from the report
  9. Set the title and summary band height to your desired height - for my example, I will set the title band height to 40 and the summary band height to 50.
  10. Now, add a Title to your report
    1. Drag the Static Text element from the palette into the Title Band
    2. Size the element to fill the title band between the margins
    3. Format the text based on how you would like the title to appear. (Increasing the font size/centering/bold, etc.)
    4. Set the text to whatever you want your Report Title to be

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.

  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"
SELECT fullname AS customer_fullname, 
country AS customer_country, 
gender AS customer_gender, 
total_children AS customer_total_children, 
occupation AS customer_occupation, 
houseowner AS customer_houseowner, 
yearly_income AS customer_income 
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 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.

  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 expected by running it within iReport.

  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 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.

  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.

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/463126.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

.NET Framewrok 4.0新增类库

转载于:https://www.cnblogs.com/tweet/archive/2010/02/08/1665805.html

在构造函数/析构函数中调用virtual函数带来的影响

在构造函数/析构函数中调用virtual函数&#xff0c;那么调用的一定是本类中的virtual函数。 先看一段代码&#xff1a; #include<iostream>class Base { public:Base() {print();}~Base() {print();}virtual void print() {std::cout << "Base::print"…

编程之美-第3章 结构之法

3.1. 字符串移位包含问题 方法1: 分别对字符串进行循环移1位,2位,3位…,来判断给定的字符串是否是其中一个字串. 复杂度是O(n^3) 方法2: 这也是一种利用空间换时间的方法. 代码如下, 为了简便实现,采用了C库中的字符串操作函数: #if 0 /** 3.1*/ bool isRotate(char *s1,char* …

每天学习一点点(2010年二月)

2010/2/8号 星期一 1.决定记录下每天学到的东西和感悟 2.看老赵的博客&#xff0c;学到一句话&#xff1a;Apple告诉我们的铁律是&#xff1a;表面功夫一定要做足。 3.看到一个笑话&#xff1a;你属什么&#xff1f;我属 于你。 2010/2/9号 星期二 1.减少页面中独立的请求数&…

InnoDB一棵B+树可以存放多少行数据?

一个问题&#xff1f; InnoDB一棵B树可以存放多少行数据&#xff1f;这个问题的简单回答是&#xff1a;约2千万。为什么是这么多呢&#xff1f;因为这是可以算出来的&#xff0c;要搞清楚这个问题&#xff0c;我们先从InnoDB索引数据结构、数据组织方式说起。 我们都知道计算…

调整路由的AD值

实验&#xff1a;调整路由的AD值【实验名称】调整路由的AD值 (注意&#xff1a;PT有可能不支持distance 99 192.168.1.2 0.0.0.0这条命令&#xff0c;所以我们做实验的时候最好用小凡模拟器)【实验目的】通过调整路由的管理距离值&#xff0c;实现路由的管理和控制【实验背景】…

C#学习日志三(流程控制语句)

if条件语句&#xff1a;根据某个条件对成都的执行进行两路分支。语法&#xff1a;if(条件){语句块1}else{语句块2}*else部分并不是必须存在的。 switch...case条件选择语句&#xff1a;当分支条件很多时&#xff0c;使用。语法&#xff1a;switch(控制表达式){case 常量表达式1…

MySQL索引的一些问题

MySQL索引的一些问题 注意&#xff1a;本文基于MySQL的InnoDB引擎说明。 一、什么是最左前缀原则 对于该表&#xff0c;如果按照name字段来建立索引的话&#xff0c;采用B树结构&#xff0c;大概的索引如下&#xff1a; 如果要进行模糊查找&#xff0c;查找name 以“张"…

线程间操作无效: 从不是创建控件“Control Name'”的线程访问它问题的解决方案及原理分析...

最近&#xff0c;在做一个使用线程控制下载文件的小程序&#xff08;使用进度条控件显示下载进度&#xff09;时&#xff0c;遇到这样的问题&#xff0c; 错误显示&#xff1a; 未处理的“System.InvalidOperationException”类型的异常出现在 System.Windows.Forms.dll 中。 其…

大家狂欢吧,我的Google帐号悲剧了

大家狂欢吧&#xff0c;我的Google帐号悲剧了 今早开始&#xff0c;鄙人在Google Code上突然被强行杯具&#xff0c;出现如下图。 最无奈的是询问Google Code管理组后得到回复如下。 然后管理员就睡觉去了|||…… 继续等待中&#xff0c;能恢复的话我会发个解决心得以警后人&am…

Hive简单实际操作(二)

两个常用的交互命令 不用启动hive就可以执行的命令 1. bin/hive -e "select * from default.animal;" 可以直接显示指定命令后的内容 2. 创建一个sql文件 vi hivef.sql 在文件内部添加你希望执行的命令例如: select * from default.animal; bin/hive -f /opt/module/…

在数据库中, 不用max()/min()找出一个列中最大/最小值的记录

不用max()/min()找出c1列中最大/最小值的记录 // 找出c1列中&#xff0c;c1是最小值的那条记录&#xff0c;不能用min() select * from t1 where c1 < all(select c1 from t1); // 找出c1列中&#xff0c;c1是最大值的那条记录&#xff0c;不能用max() select * from t1 …

C眼看J - 初窥JAVA

最近一直在学习JAVA&#xff0c;出发点并不是像当初学C那样&#xff0c;而只是想把JAVA作为下学期参加比赛的工具&#xff0c;带着这种“浮躁”的心态&#xff0c;使得我总是在想“这个用看么&#xff1f;”、“那个用看么&#xff1f;”。 这是第一次在掌握了一门语言&#xf…

为Mac OS X添加用Firefox搜索服务

为Mac OS X添加用Firefox搜索服务 在Mac OS X上&#xff0c;Firefox这种移植过来的程序往往不提供服务&#xff0c;比如只有safari才能利用服务搜索&#xff0c;经过一番实验终于自己做了一个服务&#xff1a; 第一步&#xff0c;打开Automator 第二部&#xff0c;新建一个服务…

jmeter持续集成测试中mongodb版本问题

jmeter测试mongodb&#xff0c;采用的是JSR223 Sampler脚本连接数据库&#xff0c;其中连接数据库用到了SCRAM-SHA1认证机制&#xff0c;代码如下&#xff1a; MongoCredential credential MongoCredential.createScramSha1Credential("username", "databaseN…

速度之王 — LZ4压缩算法与其他算法的比较

LZ4 (Extremely Fast Compression algorithm) 项目&#xff1a;http://code.google.com/p/lz4/ 作者&#xff1a;Yann Collet 本文作者&#xff1a;zhangskd csdn blog 简介 LZ4 is a very fast lossless compression algorithm, providing compression speed at 400MB/…

我用过的DOS命令

我用过的DOS命令 1、进入当前目录的子目录&#xff1a;cd xxx 2、放回到当前目录的上一子目录&#xff1a;cd.. 3、返回到根目录&#xff1a;cd/ 5、进入到指定目录&#xff1a;先键入指定目录的本目录如D盘&#xff1a;D: 然后回车键入cd xxx\xxx\xxx\xxx\xxx 如图&#xf…

XAMPP 无法启动解决

当安装完XAMPP后&#xff0c;在XAMPP Control Panel 里面无法启动apache,网上找了很多都是关于apache端口冲突问题&#xff0c;但我的不是&#xff0c;解决步骤如下&#xff1a;1&#xff1a;进入apache目录 conf/httpd.conf 改变监听端口&#xff1a;Listen 8080--启动任然失败…

lz4压缩算法--速度之王

简介 lz4是目前综合来看效率最高的压缩算法&#xff0c;更加侧重压缩解压速度&#xff0c;压缩比并不是第一。在当前的安卓和苹果操作系统中&#xff0c;内存压缩技术就使用的是lz4算法&#xff0c;及时压缩手机内存以带来更多的内存空间。本质上是时间换空间。 压缩原理 lz…

Mac OS defaults命令(Access the Mac OS user defaults system)

defaults命令: 用于访问和修改Mac 上一些系统的默认设置&#xff08;Access the Mac OS user defaults system&#xff09; 仅修改当前用户设置&#xff0c;所以不应加sudo。 用法&#xff1a; 读取所有默认配置&#xff1a; defaults read 读取某项配置&#xff1a; defaults …