如何使用Group By创建Jasper Report Table组件? [英] How to create Jasper Report Table component with Group By?

查看:175
本文介绍了如何使用Group By创建Jasper Report Table组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准列布局可用于实现此目的。如何为表组件布局执行此操作?

The standard column layout can use to achieve this. How can I do it for the table component layout?

推荐答案

这很容易。您应该为 Table 组件添加新数据源,然后在此组件中使用它(数据源)。

It is quite easy. You should add new datasource for Table component and then use it (datasource) in this component.

示例 jrxml

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ... whenNoDataType="AllSectionsNoDetail" ...>
    <style name="table">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="tableDataset">
        <queryString language="SQL">
            <![CDATA[SELECT id, city, street FROM address ORDER BY city]]>
        </queryString>
        <field name="ID" class="java.lang.Integer"/>
        <field name="CITY" class="java.lang.String"/>
        <field name="STREET" class="java.lang.String"/>
        <group name="CITY">
            <groupExpression><![CDATA[$F{CITY}]]></groupExpression>
        </group>
    </subDataset>
    <title>
        <band height="58" splitType="Stretch">
            <componentElement>
                <reportElement key="table" style="table" x="0" y="0" width="299" height="46"/>
                <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="tableDataset">
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    </datasetRun>
                    <jr:column width="90">
                        <jr:groupHeader groupName="CITY">
                            <jr:cell height="30" rowSpan="1">
                                <textField>
                                    <reportElement x="0" y="0" width="90" height="30"/>
                                    <textElement/>
                                    <textFieldExpression><![CDATA[$F{CITY}]]></textFieldExpression>
                                </textField>
                            </jr:cell>
                        </jr:groupHeader>
                        <jr:columnHeader style="table_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="90" height="30"/>
                                <textElement/>
                                <text><![CDATA[Id]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:columnHeader style="table_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="90" height="30"/>
                                <textElement/>
                                <text><![CDATA[Street]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$F{STREET}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </title>
</jasperReport>

iReport 中的设计如下所示:


  • 主要报告视图:


  • 组件视图:

  • The Table component view:

在此示例中,我删除了主数据源并将 Table 组件放入标题乐队。我已设置 whenNoDataType =AllSectionsNoDetail 属性以显示报告。

In this sample I've delete the main datasource and put the Table component to the Title band. I've set whenNoDataType="AllSectionsNoDetail" property for displaying report.

报告中的数据按以下方式分组: city 字段。

The data in report is grouped by city field.

这篇关于如何使用Group By创建Jasper Report Table组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆