Jump to content
We've recently updated our Privacy Statement, available here ×
  • iReport: How to introduce the page break after pre-defined number of rows in the Table component


    akonkin
    • Version: v5.1, v5.0 Product: iReport Designer

    In this short article, I want to share the information that I received from our engineering team and that I believe will be helpful for JasperReports fans :) The main goal of this article is to show how to implement the page break if the table component hit the pre-defined limit of the records per one page.

    In the sample that is described below the limit of the records after which the page break will be inserted is equal to 10.

    To implement this solution:

    • add the table component to your report

    • open the DataSet associated with this report and add to it the Group (I've called it pageBreakGroup)

    • set Group expression to

        (int)(($V{REPORT_COUNT} - 1) / 10)

    • check 'Start on a new page' property

    iReport_Design_time.png.986f933b7765cc37831354085dd66bd3.png

    iReport_runtime(1).png.6e7e9fe2286204ff0810ac23b7ac6f9e.png

    Please find in the attachment to this article the jrxml sample of the report that has been described above.

    Thank you for your attention to this article.

    Alex

     

    iReport_Design_time.png.3ee7e9d354c0e2eeb0d9542e1627bac9.png

    iReport_runtime(1).png.286939fe04624dbe2b7d9c1b89c8641b.png

    table_page_break.jrxml


    User Feedback

    Recommended Comments

    Hi Alex,

    I have treid the same in my report, and i'm able to get the pagination done, but i see some space in my report from second page onwards between the column footer and detail bands. I have tried to set the Float Column Footer property to true and also tried to reduce the page height which is of no use.

    Please help me to solve this issue, thanks in advance. Below is the corresponding .jrxml code.

     

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Created with Jaspersoft Studio version 6.9.0.final using JasperReports Library version 6.9.0-cb8f9004be492ccc537180b49c026951f4220bf3  -->
    <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="Fourth_Template" pageWidth="800" pageHeight="30235" columnWidth="760" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isFloatColumnFooter="true" uuid="3b500a3d-0b2c-409f-915c-ee0d172e9f38">
        <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter(ATT Dev DS)"/>
        <property name="net.sf.jasperreports.export.csv.exclude.origin.keep.first.band.1" value="pageHeader"/>
        <property name="net.sf.jasperreports.export.csv.exclude.origin.band.2" value="pageFooter"/>
        <property name="net.sf.jasperreports.export.csv.exclude.origin.keep.first.band.3" value="columnHeader"/>
        <property name="net.sf.jasperreports.export.csv.exclude.origin.keep.first.report.3" value="*"/>
        <property name="net.sf.jasperreports.export.csv.exclude.origin.band.4" value="columnFooter"/>
        <style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="Table_CH" mode="Opaque" backcolor="#006699">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
            <conditionalStyle>
                <conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
                <style backcolor="#AAD8F2"/>
            </conditionalStyle>
        </style>
        <subDataset name="FirmwareCreationReportByTenant_Dataset" uuid="1cd7e0c5-4726-4198-9bc5-8550b27320a9">
            <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
            <property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter(ATT Dev DS)"/>
            <parameter name="TenantName" class="java.lang.String"/>
            <parameter name="myPrereqsColl" class="java.util.Collection" nestedType="java.lang.String"/>
            <queryString language="SQL">
                <![CDATA[sELECT FI.ID,
    FWP.IMAGE_PREREQUISITE,
    FI.IMAGE_VERSION,
    FP.VALUE,
    FI.INSERTED
    FROM FIRMWARE_IMAGE FI,
    DEVICE_MODEL_CONFIG DM,
    FW_PROPERTIES FP ,
    FW_PREREQUISITE FWP,
    TENANT t
    WHERE FI.ID = FP.FIRMWARE_ID
    AND FP.NAME = 'Size'
    AND FI.ID = FWP.FIRMWARE_ID
    AND DM.ID = FI.DEVICE_MODEL_CONFIG_ID
    and t.id = fi.tenant_id
    and t.fullname = $P{TenantName}
    and $X{NOTIN, FWP.IMAGE_PREREQUISITE, myPrereqsColl}
    ORDER BY DM.MANUFACTURER,
    FI.DEVICE_MODEL_CONFIG_ID,
    FI.ID]]>
            </queryString>
            <field name="ID" class="java.math.BigDecimal">
                <property name="com.jaspersoft.studio.field.label" value="ID"/>
            </field>
            <field name="IMAGE_PREREQUISITE" class="java.lang.String">
                <property name="com.jaspersoft.studio.field.label" value="IMAGE_PREREQUISITE"/>
            </field>
            <field name="IMAGE_VERSION" class="java.lang.String">
                <property name="com.jaspersoft.studio.field.label" value="IMAGE_VERSION"/>
            </field>
            <field name="VALUE" class="java.lang.String">
                <property name="com.jaspersoft.studio.field.label" value="VALUE"/>
            </field>
            <field name="INSERTED" class="java.sql.Timestamp">
                <property name="com.jaspersoft.studio.field.label" value="INSERTED"/>
            </field>
            <group name="Group1" isStartNewPage="true">
                <groupExpression><![CDATA[(int)(($V{REPORT_COUNT} - 1) / 1000)]]></groupExpression>
            </group>
        </subDataset>
        <parameter name="TenantName" class="java.lang.String"/>
        <parameter name="myPrereqsColl" class="java.util.Collection" nestedType="java.lang.String">
            <parameterDescription><![CDATA[source Firmware Version]]></parameterDescription>
        </parameter>
        <queryString language="SQL">
            <![CDATA[select 1 from dual]]>
        </queryString>
        <field name="1" class="java.math.BigDecimal">
            <property name="com.jaspersoft.studio.field.label" value="1"/>
        </field>
        <title>
            <band height="110" splitType="Stretch">
                <frame>
                    <reportElement mode="Opaque" x="-20" y="-20" width="801" height="130" backcolor="#0973BA" uuid="fe4a6455-7dc2-44b6-9576-1635b42ff488"/>
                    <staticText>
                        <reportElement x="9" y="3" width="707" height="49" uuid="929b641f-27ef-4487-a579-8e442952566e"/>
                        <textElement>
                            <font fontName="Times New Roman" size="35" isBold="true"/>
                        </textElement>
                        <text><![CDATA[FirmwareCreationReportByTenant]]></text>
                    </staticText>
                    <staticText>
                        <reportElement x="15" y="48" width="140" height="30" uuid="a6b89ba7-4f50-4ded-a112-f0a678febabc">
                            <property name="com.jaspersoft.studio.unit.y" value="px"/>
                        </reportElement>
                        <textElement>
                            <font fontName="Times New Roman" size="18" isBold="true"/>
                        </textElement>
                        <text><![CDATA[input Params]]></text>
                    </staticText>
                    <staticText>
                        <reportElement x="14" y="77" width="150" height="29" uuid="a9bcd95e-871d-4913-9a61-efcb772a033d">
                            <property name="com.jaspersoft.studio.unit.width" value="px"/>
                        </reportElement>
                        <textElement>
                            <font fontName="Times New Roman" size="16" isBold="true"/>
                        </textElement>
                        <text><![CDATA[Tenant Name :]]></text>
                    </staticText>
                    <staticText>
                        <reportElement x="15" y="104" width="150" height="24" uuid="f25af665-d1ca-41b1-9123-da64c83b1854">
                            <property name="com.jaspersoft.studio.unit.width" value="px"/>
                        </reportElement>
                        <textElement>
                            <font fontName="Times New Roman" size="16" isBold="true"/>
                        </textElement>
                        <text><![CDATA[Prerequisite   :]]></text>
                    </staticText>
                    <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                        <reportElement x="144" y="99" width="639" height="29" uuid="cfb7a9df-4983-4e8a-a1fb-96a2d9db8260"/>
                        <textElement textAlignment="Left" verticalAlignment="Middle">
                            <font fontName="Times New Roman" size="14" isBold="true"/>
                        </textElement>
                        <textFieldExpression><![CDATA[$P{myPrereqsColl}]]></textFieldExpression>
                    </textField>
                    <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                        <reportElement x="143" y="73" width="349" height="29" uuid="2f316b97-b683-46d9-864c-82d2e54f601c"/>
                        <textElement textAlignment="Left" verticalAlignment="Middle">
                            <font fontName="Times New Roman" size="14" isBold="true"/>
                        </textElement>
                        <textFieldExpression><![CDATA[$P{TenantName}]]></textFieldExpression>
                    </textField>
                </frame>
            </band>
        </title>
        <columnHeader>
            <band height="13" splitType="Stretch"/>
        </columnHeader>
        <detail>
            <band height="60" splitType="Stretch">
                <componentElement>
                    <reportElement x="0" y="0" width="760" height="60" isRemoveLineWhenBlank="true" uuid="e490e363-8832-4c4d-b9b6-e834dbf5e372">
                        <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                        <property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
                        <property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
                        <property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
                    </reportElement>
                    <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="FirmwareCreationReportByTenant_Dataset" uuid="bc93e626-2d58-45e5-bd86-fa99c52870fb">
                            <datasetParameter name="TenantName">
                                <datasetParameterExpression><![CDATA[$P{TenantName}]]></datasetParameterExpression>
                            </datasetParameter>
                            <datasetParameter name="myPrereqsColl">
                                <datasetParameterExpression><![CDATA[$P{myPrereqsColl}]]></datasetParameterExpression>
                            </datasetParameter>
                            <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                        </datasetRun>
                        <jr:column width="60" uuid="a13b924b-be03-4909-a1ab-9e5d1ffc616d">
                            <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
                            <jr:columnHeader style="Table_CH" height="30" rowSpan="1">
                                <property name="com.jaspersoft.studio.unit.width" value="px"/>
                                <staticText>
                                    <reportElement x="0" y="0" width="60" height="30" isRemoveLineWhenBlank="true" uuid="05ee74f0-d231-4c5c-b788-7c3622d748f5"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font fontName="Times New Roman" size="14" isBold="true"/>
                                    </textElement>
                                    <text><![CDATA[s.No]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="Table_TD" height="30">
                                <property name="com.jaspersoft.studio.unit.width" value="px"/>
                                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                                    <reportElement x="0" y="0" width="60" height="30" isRemoveLineWhenBlank="true" uuid="47699efc-16a1-4aee-8392-3dd01996afe6"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="12"/>
                                    </textElement>
                                    <textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column width="160" uuid="a41f0478-7b68-470a-8682-451a9df2a093">
                            <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                            <jr:columnHeader style="Table_CH" height="30" rowSpan="1">
                                <staticText>
                                    <reportElement x="0" y="0" width="160" height="30" isRemoveLineWhenBlank="true" uuid="f4452b76-c942-4660-adac-f881f84c5120"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font fontName="Times New Roman" size="14" isBold="true"/>
                                    </textElement>
                                    <text><![CDATA[Firmware Image Id]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="Table_TD" height="30">
                                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                                    <reportElement x="0" y="0" width="160" height="30" isRemoveLineWhenBlank="true" uuid="c6713331-b205-4abc-8221-b6869376a45d"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="12" isBold="false"/>
                                    </textElement>
                                    <textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column width="170" uuid="de55a0e7-8892-441a-9942-1eb4467329e7">
                            <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column3"/>
                            <jr:columnHeader style="Table_CH" height="30" rowSpan="1">
                                <staticText>
                                    <reportElement x="0" y="0" width="170" height="30" isRemoveLineWhenBlank="true" uuid="e0500d93-5a74-4640-9dd2-745c816c7c1e"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font fontName="Times New Roman" size="14" isBold="true"/>
                                    </textElement>
                                    <text><![CDATA[image Prerequisite]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="Table_TD" height="30">
                                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                                    <reportElement x="0" y="0" width="170" height="30" isRemoveLineWhenBlank="true" uuid="33fcb37b-f84a-45a8-ad15-5057f280a1cb"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="12"/>
                                    </textElement>
                                    <textFieldExpression><![CDATA[$F{IMAGE_PREREQUISITE}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column width="125" uuid="d2f16402-49e9-4282-92a8-df32c8d77ef9">
                            <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column4"/>
                            <jr:columnHeader style="Table_CH" height="30" rowSpan="1">
                                <property name="com.jaspersoft.studio.unit.width" value="px"/>
                                <staticText>
                                    <reportElement x="0" y="0" width="125" height="30" isRemoveLineWhenBlank="true" uuid="2a8e0d65-616c-44e7-9d56-77008a2b6577"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font fontName="Times New Roman" size="14" isBold="true"/>
                                    </textElement>
                                    <text><![CDATA[image Version]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="Table_TD" height="30">
                                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                                    <reportElement x="0" y="0" width="125" height="30" isRemoveLineWhenBlank="true" uuid="49d216af-73dc-4328-8c22-9fd8ad0fe0f4"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="12"/>
                                    </textElement>
                                    <textFieldExpression><![CDATA[$F{IMAGE_VERSION}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column width="115" uuid="f0c405a4-e8ea-4a64-b2ef-26f5ff005e2a">
                            <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column5"/>
                            <jr:columnHeader style="Table_CH" height="30" rowSpan="1">
                                <property name="com.jaspersoft.studio.unit.width" value="px"/>
                                <staticText>
                                    <reportElement x="0" y="0" width="115" height="30" isRemoveLineWhenBlank="true" uuid="9a449456-7f8d-4646-a02d-aeb3dc0f6498"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font fontName="Times New Roman" size="14" isBold="true"/>
                                    </textElement>
                                    <text><![CDATA[Value]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="Table_TD" height="30">
                                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                                    <reportElement x="0" y="0" width="115" height="30" isRemoveLineWhenBlank="true" uuid="4fc77ede-18a2-4b39-a317-e8c63a88cd00"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="12"/>
                                    </textElement>
                                    <textFieldExpression><![CDATA[$F{VALUE}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column width="130" uuid="7edf61a0-9561-4d0c-bb9c-bff042d2996f">
                            <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column6"/>
                            <jr:columnHeader style="Table_CH" height="30" rowSpan="1">
                                <property name="com.jaspersoft.studio.unit.width" value="px"/>
                                <staticText>
                                    <reportElement x="0" y="0" width="130" height="30" isRemoveLineWhenBlank="true" uuid="3554760c-b8dd-45dd-8f69-6a02e8bac541"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font fontName="Times New Roman" size="14" isBold="true"/>
                                    </textElement>
                                    <text><![CDATA[inserted]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="Table_TD" height="30">
                                <textField isStretchWithOverflow="true" pattern="yyyy-MM-dd hh:mm:ss" isBlankWhenNull="true">
                                    <reportElement x="0" y="0" width="130" height="30" isRemoveLineWhenBlank="true" uuid="ae2f753a-8baa-45e8-952a-63ad4d8f76b4"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="12"/>
                                    </textElement>
                                    <textFieldExpression><![CDATA[$F{INSERTED}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                    </jr:table>
                </componentElement>
            </band>
        </detail>
        <columnFooter>
            <band height="39" splitType="Stretch">
                <property name="com.jaspersoft.studio.unit.height" value="px"/>
                <textField isStretchWithOverflow="true" pattern="EEEEE dd MMMMM yyyy" isBlankWhenNull="true">
                    <reportElement mode="Opaque" x="-1" y="9" width="761" height="30" isRemoveLineWhenBlank="true" backcolor="#006699" uuid="7bf95241-20cb-4516-bbe7-c2adf06407f4">
                        <property name="com.jaspersoft.studio.unit.height" value="px"/>
                    </reportElement>
                    <box leftPadding="20"/>
                    <textElement verticalAlignment="Middle">
                        <font fontName="Times New Roman" size="12" isBold="true"/>
                    </textElement>
                    <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="629" y="14" width="57" height="20" uuid="fa163e09-09fd-4202-bbf3-cb9b1e2f4357">
                        <property name="com.jaspersoft.studio.unit.height" value="px"/>
                    </reportElement>
                    <textElement textAlignment="Right" verticalAlignment="Middle">
                        <font fontName="Times New Roman" size="12" isBold="true"/>
                    </textElement>
                    <textFieldExpression><![CDATA["Page " + $V{PAGE_NUMBER}]]></textFieldExpression>
                </textField>
                <textField evaluationTime="Report">
                    <reportElement x="686" y="14" width="63" height="20" uuid="54b45cb3-239d-4662-910c-ba2852541bfc">
                        <property name="com.jaspersoft.studio.unit.height" value="px"/>
                    </reportElement>
                    <textElement textAlignment="Left" verticalAlignment="Middle">
                        <font fontName="Times New Roman" size="12" isBold="true"/>
                    </textElement>
                    <textFieldExpression><![CDATA[" of " + $V{PAGE_NUMBER}]]></textFieldExpression>
                </textField>
            </band>
        </columnFooter>
    </jasperReport>

     

    Nasir

    Link to comment
    Share on other sites



    Guest
    This is now closed for further comments

×
×
  • Create New...