如何处理 Jasper 中的多个组详细信息?

How to handle multiple group details in Jasper?

我有这组记录:

颜色table.

color_group | color_name | color_no
Primary     | Red        | 1
Primary     | Blue       | 3
Primary     | Yellow     | 2
Secondary   | Green      | 8
Secondary   | Violet     | 1
Secondary   | Orange     | 7
Others      | Pink       | 6
Others      | White      | 4
Others      | Black      | 5

我想生成这样的报告。

Primary
  Red        1
  Blue       3  
  Yellow     2
Secondary
  Green      8
  Violet     1
  Orange     7
Others
  Pink       6
  White      5
  Black      4

如何在 jasper 报告中这样显示?

这可以通过在 color_group 字段上使用 group 并添加 groupHeader band 来显示其值来解决。

例子

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="group" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c1d9b4b7-6162-4b17-b871-3cf3b867d1ef">
    <field name="color_group" class="java.lang.String"/>
    <field name="color_name" class="java.lang.String"/>
    <field name="color_no" class="java.lang.Integer"/>
    <group name="colorGroup">
        <groupExpression><![CDATA[$F{color_group}]]></groupExpression>
        <groupHeader>
            <band height="20">
                <textField>
                    <reportElement x="0" y="0" width="100" height="20" uuid="e98d6fc1-1ecd-4af4-8250-d8aaa497011e"/>
                    <textFieldExpression><![CDATA[$F{color_group}]]></textFieldExpression>
                </textField>
            </band>
        </groupHeader>
    </group>
    <detail>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement x="20" y="0" width="100" height="20" uuid="7ca1ac35-6249-4ba6-ac87-031f8d410d2e"/>
                <textFieldExpression><![CDATA[$F{color_name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="120" y="0" width="100" height="20" uuid="395b0cdd-4d2c-4d0b-93cd-7cad6daf3a4b"/>
                <textFieldExpression><![CDATA[$F{color_no}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

结果

据我所知,这是在 iReport 中创建和使用组的过程。

*Write desired query to fetch fields.
*Go to report name -> right click -> add report group -> 
 specify group name and group by object(in group-criteria) -> next ->
 add group-header and footer if needed(in details) -> finish.
*Use this group where ever necessary(by using 'print when group' expression 
 as created group).