【问题标题】:jasper reports grouping not working as expectedjasper 报告分组未按预期工作
【发布时间】:2020-04-23 04:11:09
【问题描述】:

我正在对选择查询运行 jasper 报告,我将结果按几个值分组,并在我的标题中使用相同的字段 下面是我的 jasper 组表达式和标题。

<groupExpression><![CDATA[$F{tray_code} + $F{card_id} + $F{card_position}+$F{card_number}+ $F{card_from_date}+ $F{card_to_date} + $F{week_number}+$F{patient_id} + $F{patient_full_name}]]></groupExpression>
    <groupHeader>
        <band height="15">
            <textField isBlankWhenNull="true">
                <reportElement x="5" y="0" width="20" height="14" uuid="97fd5e2c-50e4-46e4-9c1b-0453f5cd05b5"/>
                <textElement>
                    <font fontName="DejaVu Sans" size="8" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{tray_code}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement x="26" y="0" width="44" height="14" uuid="d16ea2fb-367a-4b5e-986e-bc19669c3091"/>
                <textElement>
                    <font fontName="DejaVu Sans" size="8" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{card_id}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="95" y="0" width="25" height="14" uuid="b7eb1f75-44d4-467e-8463-29f6f6f4555b"/>
                <textElement textAlignment="Center">
                    <font fontName="DejaVu Sans" size="8" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{card_position}]]></textFieldExpression>
            </textField>
            <textField pattern="">
                <reportElement x="120" y="0" width="55" height="14" uuid="10e4bc1b-cfbb-478d-bd10-a6284bd3bac1"/>
                <textElement>
                    <font fontName="DejaVu Sans" size="8" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[new SimpleDateFormat("dd/MM/yyyy").format(new SimpleDateFormat("yyyy-MM-dd").parse($F{card_from_date}))]]></textFieldExpression>
            </textField>
            <textField pattern="dd/MM/yyyy">
                <reportElement x="175" y="0" width="55" height="14" uuid="a7d34de5-c4de-4093-9da7-96119450c3ab"/>
                <textElement>
                    <font fontName="DejaVu Sans" size="8" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[new SimpleDateFormat("dd/MM/yyyy").format(new SimpleDateFormat("yyyy-MM-dd").parse($F{card_to_date}))]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="230" y="0" width="24" height="14" uuid="9cf3bce2-cb70-45e7-8199-0d6c8003ce53"/>
                <textElement>
                    <font fontName="DejaVu Sans" size="8" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{week_number}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="270" y="0" width="67" height="14" uuid="d9e50bb7-1616-4d84-b92f-246abd05ae7b"/>
                <textElement>
                    <font fontName="DejaVu Sans" size="8" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{patient_id}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="337" y="0" width="250" height="14" uuid="b06f0d0d-739b-4e2a-a2bc-1686c9d5cbfe"/>
                <textElement>
                    <font fontName="DejaVu Sans" size="8" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{patient_full_name}]]></textFieldExpression>
            </textField>
            <line>
                <reportElement x="0" y="14" width="752" height="1" uuid="968c2e25-462d-4b0a-90e2-34570db25d0f"/>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Dashed" lineColor="#999999"/>
                </graphicElement>
            </line>
            <textField>
                <reportElement x="70" y="0" width="25" height="14" uuid="7f4ba299-706f-4ba6-aafc-ffa47b0e4374"/>
                <textElement textAlignment="Center">
                    <font fontName="DejaVu Sans" size="8" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{card_number}]]></textFieldExpression>
            </textField>
        </band>
    </groupHeader>

根据上面的组表达式,我希望一个组只有一个标题,但我看到同一组的组标题在我的输出文件中重复!请让我知道我做错了什么。 提前致谢。

【问题讨论】:

  • 当您在 Jasper 中处理乐队乐队时,应该对数据进行排序。
  • 我已经根据 Patient_full_name 对数据进行了排序。
  • 另外,如果我只使用一列进行分组,它会起作用,当我添加第二列时,我就会看到问题。
  • 数据应该按照您在分组中的排序方式进行排序。

标签: jasper-reports


【解决方案1】:

因此,当您使用多个组标题时会出现问题。第一个标题的行为与预期的一样,仅在唯一值上按列值 A 排序。 使用列值 B 的第二个标题将打印在每一行上,尽管它是非唯一值。 理论上你应该可以使用:

1.

ORDER BY ValueA, ValueB

假设您正在使用 sql、plsql 等来正确显示报告... 但是,就我而言,这并没有发生,尽管对其他人来说似乎有效。

2。 使用子报告通过独特的报告附加细微的差异。 您创建一个包含空详细信息的根报告。 然后您创建独特的报告作为子报告。 最后,您使用子报表元素将值链接到根报表。虽然这是一项很好的工作,并且可能会导致重复代码。

  1. 我使用的一个 hacky 方法是: “Print When Expressions”与逻辑布尔值的混合,如下所示
$F{QUERY}.equals(Query1) && ($P{P_Typequery}.equalsIgnoreCase("QueryA") && $P{P_parameter} == null) 

$F{QUERY}.equals(Query1) && ($P{P_Typequery}.equalsIgnoreCase("P_QueryA") && $P{P_parameter} != null) 

具有两个组标题和一个列标题。列标题不会为每一行重复,因此您将其中一个布尔表达式分配给它的“打印时间”,因此它并不总是打印。第一个组标题不会对每一行重复并且有效。第二组标题用于您希望它为每个唯一值重复的时间,因为它总是为每一行打印,并且您在它的“打印时间”上使用另一个布尔值。 希望对你有帮助

【讨论】:

    猜你喜欢
    • 2012-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-16
    相关资源
    最近更新 更多