Jump to content
Changes to the Jaspersoft community edition download ×
  • Sample Report To Demo How to Display Fixed Number of Grid Row Per Page


    tchen
    • Version: v6.2.1 Product: JasperReports® Library

    This report will demonstrate the approach to meet the following requirement:

    - Report has fixed number of rows per page
    - Report cell has grid borders

    Report is designed in Jasper Studio JSS version 6.2.1 and can be tested using JasperReports Server JRS repository PostgreSQL database.

    Technique used in this report:

    - using PostgreSQL n generator query to create n rows of null record to fill the last page of the report

    SELECT NULL as id, null as name FROM generate_series(1, n) i

    - using unprepared JR parameter $P!{} to inject limit into report query to ensure total report count is evenly dividable by the number of columns per page.

    limit $P!{Parameter4}
    

    - using page break on group change based on the number of columns per page record chunk increment

        <group name="Group1" isStartNewPage="true">
            <groupExpression><![CDATA[($V{REPORT_COUNT}.intValue()-1)/$P{NumberOfRecordsPerPage}.intValue()]]></groupExpression>
        </group>
    



    Report Design Template (JRXML file):

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Created with Jaspersoft Studio version 6.2.1.final using JasperReports Library version 6.2.1  -->
    <!-- 2016-05-18T10:14:47 -->
    <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="demo-fill-page sql" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f72954d9-1374-4ee3-87dc-c38c08d214c4">
        <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="JRSrepo"/>
        <parameter name="NumberOfRecords" class="java.lang.Integer">
            <parameterDescription><![CDATA[]]></parameterDescription>
            <defaultValueExpression><![CDATA[50]]></defaultValueExpression>
        </parameter>
        <parameter name="NumberOfRecordsPerPage" class="java.lang.Integer">
            <defaultValueExpression><![CDATA[20]]></defaultValueExpression>
        </parameter>
        <parameter name="DisplayCalculation" class="java.lang.Boolean">
            <parameterDescription><![CDATA[]]></parameterDescription>
            <defaultValueExpression><![CDATA[false]]></defaultValueExpression>
        </parameter>
        <parameter name="Parameter3" class="java.lang.Integer" isForPrompting="false">
            <defaultValueExpression><![CDATA[$P{NumberOfRecords}.intValue()%$P{NumberOfRecordsPerPage}.intValue()]]></defaultValueExpression>
        </parameter>
        <parameter name="Parameter4" class="java.lang.Integer" isForPrompting="false">
            <defaultValueExpression><![CDATA[$P{Parameter3}.intValue()==0?$P{NumberOfRecords}:$P{NumberOfRecords}.intValue()+$P{NumberOfRecordsPerPage}.intValue()-$P{Parameter3}.intValue()]]></defaultValueExpression>
        </parameter>
        <queryString>
            <![CDATA[select * from (
    select * from (
    select id, name from jiresource
    order by name
    limit  $P!{NumberOfRecords}
    ) t
    union all
    SELECT NULL as id, null as name FROM generate_series(1, $P!{NumberOfRecordsPerPage} ) i
    ) t2
    limit $P!{Parameter4} ]]>
        </queryString>
        <field name="id" class="java.lang.Long"/>
        <field name="name" class="java.lang.String"/>
        <group name="Group1" isStartNewPage="true">
            <groupExpression><![CDATA[($V{REPORT_COUNT}.intValue()-1)/$P{NumberOfRecordsPerPage}.intValue()]]></groupExpression>
        </group>
        <background>
            <band splitType="Stretch"/>
        </background>
        <title>
            <band height="30" splitType="Stretch">
                <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                <printWhenExpression><![CDATA[$P{DisplayCalculation}.booleanValue()]]></printWhenExpression>
                <textField>
                    <reportElement x="0" y="0" width="100" height="30" uuid="3923ad1e-ea3a-41db-8be1-7702d75ad3a0"/>
                    <textFieldExpression><![CDATA[$P{NumberOfRecords}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="100" y="0" width="100" height="30" uuid="069d1501-b09b-4a35-b49e-6ef5199dce74"/>
                    <textFieldExpression><![CDATA[$P{NumberOfRecordsPerPage}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="200" y="0" width="100" height="30" uuid="d1084cca-8b3a-4e9d-920b-e88861e4236f"/>
                    <textFieldExpression><![CDATA[$P{Parameter3}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="300" y="0" width="100" height="30" uuid="6b1f4375-7cdf-4a24-9fb3-0f8fb9570d1a"/>
                    <textFieldExpression><![CDATA[$P{Parameter4}]]></textFieldExpression>
                </textField>
            </band>
        </title>
        <pageHeader>
            <band splitType="Stretch">
                <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
            </band>
        </pageHeader>
        <columnHeader>
            <band height="40" splitType="Stretch">
                <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                <staticText>
                    <reportElement x="50" y="0" width="100" height="30" uuid="3b2355d8-83ed-4c11-a23b-67fabc4ccfdc">
                        <property name="com.jaspersoft.studio.unit.x" value="pixel"/>
                    </reportElement>
                    <text><![CDATA[id]]></text>
                </staticText>
                <staticText>
                    <reportElement x="150" y="0" width="430" height="30" uuid="e0cfdec9-0486-4b42-862c-a44861b3d9f7">
                        <property name="com.jaspersoft.studio.unit.x" value="pixel"/>
                    </reportElement>
                    <text><![CDATA[name]]></text>
                </staticText>
            </band>
        </columnHeader>
        <detail>
            <band height="30" splitType="Stretch">
                <textField isBlankWhenNull="true">
                    <reportElement x="50" y="0" width="100" height="30" uuid="af909aec-171a-4d64-b75b-8ef5f8f6317d">
                        <property name="com.jaspersoft.studio.unit.y" value="pixel"/>
                        <property name="com.jaspersoft.studio.unit.x" value="pixel"/>
                    </reportElement>
                    <box>
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
                </textField>
                <textField isBlankWhenNull="true">
                    <reportElement x="150" y="0" width="430" height="30" uuid="90219a05-903a-40f5-94fa-2557fc3a8988">
                        <property name="com.jaspersoft.studio.unit.y" value="pixel"/>
                        <property name="com.jaspersoft.studio.unit.x" value="pixel"/>
                    </reportElement>
                    <box>
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="0" y="0" width="50" height="30" uuid="a970311a-d78b-4f68-b93f-9a22443f51fe"/>
                    <textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
                </textField>
            </band>
        </detail>
        <columnFooter>
            <band splitType="Stretch">
                <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
            </band>
        </columnFooter>
        <pageFooter>
            <band splitType="Stretch">
                <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
            </band>
        </pageFooter>
        <summary>
            <band splitType="Stretch">
                <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
            </band>
        </summary>
    </jasperReport>



    Report output:

    demo-fill-pagesql-50-20-1.png.21f5d3fe0eae6ced9d6a65f72bba114b.png

    demo-fill-pagesql-50-20-2.png.42760711e5cd2ec404571f3e7849936d.png

    demo-fill-pagesql-50-20-3.png.5673c29e3f35f7b9a80cb40c34837134.png


    ===========================================
    TTC-20160518


    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...