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

Home » Wiki » Getting Started with the Table Component

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

Getting Started with the Table Component相关推荐

  1. Pentaho BI server 中 CCC table Component 的使用小技巧

    我使用的版本 Pentaho BI Server 5.3.0.0.213 CDE/CDF/CDA/CCC 15.04.16 stable Q: 如何设置表格中各种提示文字的语言(默认为英语)? CDE ...

  2. SAP Spartacus 里的三种table类型

    定义在文件table.component.html里: verticalStackedLayout verticalLayout horizontalLayout 从每种类型的ng-container ...

  3. SAP Spartacus和Table相关的配置结构ResponsiveTableConfiguration

    ResponsiveTableConfiguration的父类是TableStructureConfiguration: export interface TableStructureConfigur ...

  4. angular primeng table 非sortIcon排序

    功能目标: 点击表格中一行,可向上.向下调整顺序.如下图,点[向下]按钮后第一行.第二行交换顺序.      组件:LayersWindow 利用primeng的table实现表格功能,html如下 ...

  5. React will try to recreate this component tree from scratch using the error boundary you provided,

    使用ntd.pro提供的protable时,碰到个问题.其实是无意间碰到的,我只是修改了一个表的参数,导致整个表格用不了,错误信息指向了某个函数未定义或者不是一个函数,正常情况下是不会出现这种情况的, ...

  6. reac组件,Component 与 PureComponent

    我们可以看到react提供了两种组件的类型,一开始学习的时候都是使用Component,但是React提供了另外一个 PureComponent, 纯组件,目的是: 优化渲染 import React ...

  7. element ui 图片控件 排序_JAVA全栈面试前端基础之四 Vue+Element框架快速开发

    本文主要包括以下4个内容 什么是ElementUI Vue 中引入ElementUI Vue+elementUI构建后台管理系统 开源项目推荐 1.什么是ElementUI 官网:https://el ...

  8. JACK——AgentManual5 Events

    来源:http://aosgrp.com/ 5 Events 5.1 What are Events? Events motivate an agent to take action. There a ...

  9. electron仿百度网盘-UI搭建思路

    前言 https://juejin.im/editor/posts/5c167c2ff265da6167203868 实例展示 代码库 求赞鸭: https://github.com/sparkxxx ...

最新文章

  1. vue代码转换成小程序
  2. PHP生成订单号的五种方法:时间拼接随机数 混拼字母 减年份转十六进制 雪花算法 拼接时间戳与随机数
  3. 【网】关于 Blog 和 RSS 的全面介绍
  4. ubuntu搭建zookeeper集群
  5. oracle中schema指的是什么?
  6. 调用可能未定义的方法 attachVideo (通过 static 类型 flash.media:Video 引用)解决办法
  7. java 的分类_java的基本类型(转)
  8. Java 三大特性之——继承
  9. [SCOI2009]最长距离
  10. 作者:熊贇(1980-),女,博士,复旦大学计算机科学技术学院教授。
  11. mysql 替换 汉字_MySQL替换文字
  12. foreach和while的区别(编译之后)_C++学习大纲:条件编译
  13. CentOS 6 安装最新的 Redis 2.8 ,安装 TCMalloc
  14. 【测试】对手机拍照测试用例的设计
  15. 如何用python计算年龄_python根据出生日期计算年龄的代码
  16. 使用vue-ui可视化管理工具来创建项目并安装vue-cli-plugin-element插件
  17. 基于cnn的人脸识别_人脸识别技术:从传统方法到深度学习
  18. Windows下UI自动化工具Inspect
  19. HYS与七夕节大作战 vijos
  20. jieba分词自定义dict字典

热门文章

  1. setsockopt()用法(参数详细说明)
  2. 推荐算法--其他信息(07)
  3. 区块链技术指南 第一章 区块链和比特币的初体验
  4. 人生一世 什么真正的才是你的?
  5. 百万用户规模的系统如何扩展
  6. 迈出从3K到1W的重要一步——掌握设计模式
  7. 新兴的多媒体格式——MXF 文件格式分析 和简介
  8. VUE.JS 组件化开发实践
  9. LiveGBS高性能GB28181国标流媒体服务流传输模式支持UDP、TCP被动、TCP主动模式
  10. 精读《V8 引擎 Lazy Parsing》