Jasper Reports,为整个组使用单一标签

发布于 2024-12-17 06:14:39 字数 600 浏览 1 评论 0原文

我必须使用 Jasper Report 库和 iReport 创建报告。 报告中使用了数据分组。它应该以如下方式显示:

g    a_line_in_the_group
r    a_line_in_the_group
o    a_line_in_the_group
u    a_line_in_the_group
p    a_line_in_the_group
1    a_line_in_the_group

g    a_line_in_the_group
r    a_line_in_the_group
o    a_line_in_the_group
u    a_line_in_the_group
p    a_line_in_the_group
2    a_line_in_the_group

因此,一个组有一个标签。数据已分组,但标签仅显示在第一行,如下所示:

group1    a_line_in_the_group
          a_line_in_the_group
          a_line_in_the_group

我已为标签指定了属性 stretch,但它没有帮助。

I have to create a report using Jasper Report library and iReport.
In the report is used data grouping. It should be shown in the next way:

g    a_line_in_the_group
r    a_line_in_the_group
o    a_line_in_the_group
u    a_line_in_the_group
p    a_line_in_the_group
1    a_line_in_the_group

g    a_line_in_the_group
r    a_line_in_the_group
o    a_line_in_the_group
u    a_line_in_the_group
p    a_line_in_the_group
2    a_line_in_the_group

So there is a single label for a group. The data is grouped, but the label is shown only in the first line, like this:

group1    a_line_in_the_group
          a_line_in_the_group
          a_line_in_the_group

I've specified the property stretch for the label, but it doesn't help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

堇年纸鸢 2024-12-24 06:14:39

您可以将详细信息行放在组标签旁边...但您只能使用子报表来完成此操作。

在大多数情况下(我的意思是绝大多数情况),最简单也是最好的方法是将组标签显示在组标题中或仅显示在详细信息带中。在后一种情况下,它可以仅包含在组中的第一行或每一行中。 Alex K 的例子完美地展示了这些。

但是,当您确实希望组标签显示在详细信息旁边时,那么您将需要一个子报表。以下是它在 iReport 中的外观示例:
report layout

以下是预览时报表的呈现方式:

在此处输入图像描述

在我的示例中,我设置了组标签旋转。这在 PDF 中非常好,但在 HTML 中却不太好。但这只是一个细节;您可以随心所欲地呈现该标签。

You can put the detail rows next to the group label... but you'll only be able to do it using a subreport.

In most cases (and I mean a really overwhelming majority of cases) it is easiest and best to display the group label either into the group header or just displayed in the detail band. In the latter case it can be included on just the first row in the group or in every row. Alex K's example shows these perfectly.

But when you're in a case where you really want the group label to appear next to the details, then you'll need a subreport. Here's an example of how it would look in iReport:
report layout

Here's how that report renders when previewed:

enter image description here

In my example I set the group label rotation. This is great in PDF, but not so great in HTML. But that's just a detail; you can render that label however you like.

北城半夏 2024-12-24 06:14:39

  • 第一个变体
  •     <queryString>
            <![CDATA[SELECT
         DOCUMENTID AS POSITIONS_DOCUMENTID,
         POSITIONNO AS POSITIONS_POSITIONNO,
         PRODUCTID AS POSITIONS_PRODUCTID,
         QUANTITY AS POSITIONS_QUANTITY,
         PRICE AS POSITIONS_PRICE
    FROM
         POSITIONS order by PRODUCTID]]>
        </queryString>
        <field name="POSITIONS_DOCUMENTID" class="java.lang.Integer"/>
        <field name="POSITIONS_POSITIONNO" class="java.lang.Integer"/>
        <field name="POSITIONS_PRODUCTID" class="java.lang.Integer"/>
        <field name="POSITIONS_QUANTITY" class="java.lang.Integer"/>
        <field name="POSITIONS_PRICE" class="java.math.BigDecimal"/>
        <group name="productid">
            <groupExpression><![CDATA[$F{POSITIONS_PRODUCTID}]]></groupExpression>
            <groupHeader>
                <band height="21">
                    <textField>
                        <reportElement x="0" y="0" width="100" height="21"/>
                        <textElement/>
                        <textFieldExpression><![CDATA["Grouped by: " + $F{POSITIONS_PRODUCTID}]]></textFieldExpression>
                    </textField>
                </band>
            </groupHeader>
        </group>
        <detail>
            <band height="21" splitType="Stretch">
                <textField>
                    <reportElement x="136" y="0" width="100" height="21"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{POSITIONS_POSITIONNO}]]></textFieldExpression>
                </textField>
                <staticText>
                    <reportElement x="36" y="0" width="100" height="21"/>
                    <textElement/>
                    <text><![CDATA[Static text]]></text>
                </staticText>
            </band>
        </detail>
    

    结果将是:

    在此处输入图像描述

  • The第二个变体
  •     <queryString>
            <![CDATA[SELECT
         DOCUMENTID AS POSITIONS_DOCUMENTID,
         POSITIONNO AS POSITIONS_POSITIONNO,
         PRODUCTID AS POSITIONS_PRODUCTID,
         QUANTITY AS POSITIONS_QUANTITY,
         PRICE AS POSITIONS_PRICE
    FROM
         POSITIONS order by PRODUCTID]]>
        </queryString>
        <field name="POSITIONS_DOCUMENTID" class="java.lang.Integer"/>
        <field name="POSITIONS_POSITIONNO" class="java.lang.Integer"/>
        <field name="POSITIONS_PRODUCTID" class="java.lang.Integer"/>
        <field name="POSITIONS_QUANTITY" class="java.lang.Integer"/>
        <field name="POSITIONS_PRICE" class="java.math.BigDecimal"/>
        <group name="productid">
            <groupExpression><![CDATA[$F{POSITIONS_PRODUCTID}]]></groupExpression>
            <groupHeader>
                <band height="21"/>
            </groupHeader>
        </group>
        <detail>
            <band height="21" splitType="Stretch">
                <textField>
                    <reportElement x="136" y="0" width="100" height="21"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{POSITIONS_POSITIONNO}]]></textFieldExpression>
                </textField>
                <textField isBlankWhenNull="true">
                    <reportElement x="36" y="1" width="100" height="20">
                        <printWhenExpression><![CDATA[$V{productid_COUNT}==1]]></printWhenExpression>
                    </reportElement>
                    <textElement/>
                    <textFieldExpression><![CDATA["Grouped by: " + $F{POSITIONS_PRODUCTID}]]></textFieldExpression>
                </textField>
            </band>
        </detail>
    

    结果将是:
    在此处输入图像描述

  • The first variant
  •     <queryString>
            <![CDATA[SELECT
         DOCUMENTID AS POSITIONS_DOCUMENTID,
         POSITIONNO AS POSITIONS_POSITIONNO,
         PRODUCTID AS POSITIONS_PRODUCTID,
         QUANTITY AS POSITIONS_QUANTITY,
         PRICE AS POSITIONS_PRICE
    FROM
         POSITIONS order by PRODUCTID]]>
        </queryString>
        <field name="POSITIONS_DOCUMENTID" class="java.lang.Integer"/>
        <field name="POSITIONS_POSITIONNO" class="java.lang.Integer"/>
        <field name="POSITIONS_PRODUCTID" class="java.lang.Integer"/>
        <field name="POSITIONS_QUANTITY" class="java.lang.Integer"/>
        <field name="POSITIONS_PRICE" class="java.math.BigDecimal"/>
        <group name="productid">
            <groupExpression><![CDATA[$F{POSITIONS_PRODUCTID}]]></groupExpression>
            <groupHeader>
                <band height="21">
                    <textField>
                        <reportElement x="0" y="0" width="100" height="21"/>
                        <textElement/>
                        <textFieldExpression><![CDATA["Grouped by: " + $F{POSITIONS_PRODUCTID}]]></textFieldExpression>
                    </textField>
                </band>
            </groupHeader>
        </group>
        <detail>
            <band height="21" splitType="Stretch">
                <textField>
                    <reportElement x="136" y="0" width="100" height="21"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{POSITIONS_POSITIONNO}]]></textFieldExpression>
                </textField>
                <staticText>
                    <reportElement x="36" y="0" width="100" height="21"/>
                    <textElement/>
                    <text><![CDATA[Static text]]></text>
                </staticText>
            </band>
        </detail>
    

    The result will be:

    enter image description here

  • The second variant
  •     <queryString>
            <![CDATA[SELECT
         DOCUMENTID AS POSITIONS_DOCUMENTID,
         POSITIONNO AS POSITIONS_POSITIONNO,
         PRODUCTID AS POSITIONS_PRODUCTID,
         QUANTITY AS POSITIONS_QUANTITY,
         PRICE AS POSITIONS_PRICE
    FROM
         POSITIONS order by PRODUCTID]]>
        </queryString>
        <field name="POSITIONS_DOCUMENTID" class="java.lang.Integer"/>
        <field name="POSITIONS_POSITIONNO" class="java.lang.Integer"/>
        <field name="POSITIONS_PRODUCTID" class="java.lang.Integer"/>
        <field name="POSITIONS_QUANTITY" class="java.lang.Integer"/>
        <field name="POSITIONS_PRICE" class="java.math.BigDecimal"/>
        <group name="productid">
            <groupExpression><![CDATA[$F{POSITIONS_PRODUCTID}]]></groupExpression>
            <groupHeader>
                <band height="21"/>
            </groupHeader>
        </group>
        <detail>
            <band height="21" splitType="Stretch">
                <textField>
                    <reportElement x="136" y="0" width="100" height="21"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{POSITIONS_POSITIONNO}]]></textFieldExpression>
                </textField>
                <textField isBlankWhenNull="true">
                    <reportElement x="36" y="1" width="100" height="20">
                        <printWhenExpression><![CDATA[$V{productid_COUNT}==1]]></printWhenExpression>
                    </reportElement>
                    <textElement/>
                    <textFieldExpression><![CDATA["Grouped by: " + $F{POSITIONS_PRODUCTID}]]></textFieldExpression>
                </textField>
            </band>
        </detail>
    

    The result will be:
    enter image description here

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文