How to display one group per page using Jasper Reports

jasper-reports

I'm using iReport to create a Jasper Report template, and I need to display one group per page:

  • Group 1: (Page One)
    -Field1 Field2 Field3

  • Group 2: (Page Two)
    -Field1 Field2 Field3

And so on.

I tried setting the Maximize Band Height property to true in the "Group Footer" band using iReport, but some empty pages are added when I try to review.

Best Answer

You can use isStartNewPage attribute of group.

You can add Group Header band and

1) set "Start on a new page" attribute as true

2) set band height as 0 (if you don't need it).

The working sample

The jrxml file:

<?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_break" language="groovy" pageWidth="400" pageHeight="400" columnWidth="360" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2bcb6f3d-2169-44f6-9e8a-db54ea21b5e0">
    <queryString>
        <![CDATA[SELECT DOCUMENTID, PRODUCTID, PRICE FROM POSITIONS ORDER BY DOCUMENTID]]>
    </queryString>
    <field name="DOCUMENTID" class="java.lang.Integer"/>
    <field name="PRODUCTID" class="java.lang.Integer"/>
    <field name="PRICE" class="java.math.BigDecimal"/>
    <group name="docId" isStartNewPage="true">
        <groupExpression><![CDATA[$F{DOCUMENTID}]]></groupExpression>
        <groupHeader>
            <band/>
        </groupHeader>
    </group>
    <columnHeader>
        <band height="20" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="111" height="20" uuid="596f5fb4-7e6d-4e7e-88bf-b9c37d0fb1a1"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Center"/>
                <text><![CDATA[Position]]></text>
            </staticText>
            <staticText>
                <reportElement x="111" y="0" width="111" height="20" uuid="4884f663-00cf-4b5f-9cc1-05d698b8154a"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Center"/>
                <text><![CDATA[Id]]></text>
            </staticText>
            <staticText>
                <reportElement x="222" y="0" width="111" height="20" uuid="26c8d18f-2281-405c-a41b-bddcbcdebdbb"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Center"/>
                <text><![CDATA[Price]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement x="0" y="0" width="111" height="20" uuid="fb6369eb-4b92-41dd-b5b8-94a9210bf315"/>
                <box leftPadding="10">
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textFieldExpression><![CDATA[$F{DOCUMENTID}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="111" y="0" width="111" height="20" uuid="9fcbb785-06fa-4f7a-bc6d-301cc8db4388"/>
                <box leftPadding="10">
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textFieldExpression><![CDATA[$F{PRODUCTID}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="222" y="0" width="111" height="20" uuid="0d18c9fe-5a70-4890-b94d-f26d88bc97da"/>
                <box leftPadding="10">
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textFieldExpression><![CDATA[$F{PRICE}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <pageFooter>
        <band height="50">
            <textField>
                <reportElement x="0" y="20" width="80" height="20" uuid="47486fe9-e21f-4913-a9c4-cef0d3e2df39"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report">
                <reportElement x="80" y="20" width="40" height="20" uuid="0f7df66b-bbe6-4373-962e-519584c44541"/>
                <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
        </band>
    </pageFooter>
</jasperReport>

The result

The output result generated in iReport via preview mode

enter image description here

Related Topic