How to prevent repetition of data display in report?
Asked Answered
L

3

2

Sample Report - Design

My Sample Report - Design

Sample Report - Preview

enter image description here

XML Code 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="report2" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="82a3ce80-bdcd-4d51-8f21-e72b3f438b53">
    <style name="table">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
        <conditionalStyle>
            <conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
            <style backcolor="#EFF7FF"/>
        </conditionalStyle>
    </style>
    <style name="table 1">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
        <conditionalStyle>
            <conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
            <style backcolor="#EFF7FF"/>
        </conditionalStyle>
    </style>
    <subDataset name="dataset1" uuid="70653a81-8d48-4edd-b72f-20f769f51aea">
        <queryString language="SQL">
            <![CDATA[SELECT
     schooldetails.`ID` AS schooldetails_ID,
     schooldetails.`Name` AS schooldetails_Name,
     schooldetails.`Boardtype` AS schooldetails_Boardtype,
     schooldetails.`Location` AS schooldetails_Location,
     schooldetails.`Phone` AS schooldetails_Phone,
     schooldetails.`Address` AS schooldetails_Address,
     schooldetails.`Additionaldetails` AS schooldetails_Additionaldetails
FROM
     `schooldetails` schooldetails]]>
        </queryString>
        <field name="schooldetails_ID" class="java.lang.Integer"/>
        <field name="schooldetails_Name" class="java.lang.String"/>
        <field name="schooldetails_Boardtype" class="java.lang.String"/>
        <field name="schooldetails_Phone" class="java.lang.String"/>
    </subDataset>
    <queryString>
        <![CDATA[SELECT
     schooldetails.`ID` AS schooldetails_ID,
     schooldetails.`Name` AS schooldetails_Name,
     schooldetails.`Boardtype` AS schooldetails_Boardtype,
     schooldetails.`Location` AS schooldetails_Location,
     schooldetails.`Phone` AS schooldetails_Phone,
     schooldetails.`Address` AS schooldetails_Address,
     schooldetails.`Additionaldetails` AS schooldetails_Additionaldetails
FROM
     `schooldetails` schooldetails]]>
    </queryString>
    <field name="schooldetails_ID" class="java.lang.Integer"/>
    <field name="schooldetails_Name" class="java.lang.String"/>
    <field name="schooldetails_Boardtype" class="java.lang.String"/>
    <field name="schooldetails_Location" class="java.lang.String"/>
    <field name="schooldetails_Phone" class="java.lang.String"/>
    <field name="schooldetails_Address" class="java.lang.String"/>
    <field name="schooldetails_Additionaldetails" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch">
            <staticText>
                <reportElement uuid="e15d9fdb-5a73-421d-8059-3e6d84742a43" x="0" y="0" width="555" height="79"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="24" isBold="true"/>
                </textElement>
                <text><![CDATA[Sample report 2]]></text>
            </staticText>
        </band>
    </title>
    <detail>
        <band height="114">
            <componentElement>
                <reportElement uuid="0752ad71-0544-4a92-bc06-666619eada15" key="table 1" style="table 1" x="0" y="0" width="360" height="50"/>
                <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="dataset1" uuid="46c3a1a8-1e2b-4ea0-b7ac-5b630657c146">
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    </datasetRun>
                    <jr:column width="99" uuid="b4badcbe-8219-4fcf-978c-b5ff6f2057d0">
                        <jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement uuid="09f0cb22-b9b2-499a-9e94-0d9edb96e5f8" x="0" y="0" width="99" height="30"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="14" isBold="true"/>
                                </textElement>
                                <text><![CDATA[School ID]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table 1_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement uuid="0be272c3-3345-48fd-b90a-a0d0df3bc909" x="0" y="0" width="99" height="20"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="12"/>
                                </textElement>
                                <textFieldExpression><![CDATA[$F{schooldetails_ID}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="160" uuid="1f036ef4-d3e4-4113-9084-5530b1e3e8d2">
                        <jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement uuid="9ef54b86-c6ac-4f0b-8904-ff82ace55d7c" x="0" y="0" width="160" height="30"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="14" isBold="true"/>
                                </textElement>
                                <text><![CDATA[Name]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table 1_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement uuid="6c01ebc8-165d-41da-b632-8b19b67770ac" x="0" y="0" width="160" height="20"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="12"/>
                                </textElement>
                                <textFieldExpression><![CDATA[$F{schooldetails_Name}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="114" uuid="7561e583-3af8-4799-ac88-2a7e8c164bfa">
                        <jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement uuid="c500ce42-e32d-4704-9832-52d7413926e3" x="0" y="0" width="114" height="30"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="14" isBold="true"/>
                                </textElement>
                                <text><![CDATA[Board]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table 1_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement uuid="da078d0e-c6fb-4a3d-a0ed-ea12265cf729" x="0" y="0" width="114" height="20"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="12"/>
                                </textElement>
                                <textFieldExpression><![CDATA[$F{schooldetails_Boardtype}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="131" uuid="7842fd3f-e097-4acd-a1ab-a09c0361c23b">
                        <jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement uuid="c0519344-d25a-4ed9-8970-1acf9e4857ed" x="0" y="0" width="131" height="30"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="14" isBold="true"/>
                                </textElement>
                                <text><![CDATA[Phone]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table 1_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement uuid="560916c9-e02a-40c9-a7af-a63d285b900a" x="0" y="0" width="131" height="20"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="12"/>
                                </textElement>
                                <textFieldExpression><![CDATA[$F{schooldetails_Phone}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
</jasperReport>

My Question

How can i avoid repetition of table display twice? I want the data to be displayed only one time.

As you see in the above screen shots, I don't want the data to be displayed twice.

Leighton answered 19/3, 2013 at 16:17 Comment(0)
O
2

You have put your table component into the detail band. The detail band is repeated for every record in the dataset. You have two records, so your table is repeated twice; If you had more data, you would get many more repetitions.

You could get rid of the table component completely, putting each columnHeader element from the table into a <columnHeader> band, and each detailCell element into a <detail> band. Doing this should preserve the behaviour of the table component without repeating it. See http://community.jaspersoft.com/wiki/designing-report for an example of this.

Alternatively, you could simply move your table component into a different band that doesn't get repeated (e.g. <summary>).

Odessa answered 20/3, 2013 at 16:26 Comment(2)
thanks.. i already used this.. but was expecting whether there is a solution for using Table itself in the Detail band.. but since it wont work, i'm now using the summary band.. thanks for your replies.Leighton
@Dreamer: If you really need to put it in the detail band, you could try setting the printWhenExpression on the table to $V{REPORT_COUNT} == 1Odessa
D
1

Copy the table component in summary band and delete the detail band.

If you want repeated value in table data then edit your table component in Ireport and select the text field and uncheck the "Print Repeated Values" check box property of a text field.

XML CODE will be like this:-

          </jr:columnHeader>
          <jr:detailCell style="table 1_TD" height="20" rowSpan="1">
             <textField>
                <reportElement uuid="560916c9-e02a-40c9-a7af-a63d285b900a" 
          isPrintRepeatedValues="false" x="0" y="0" width="131" height="20"/>
             <textElement textAlignment="Center" verticalAlignment="Middle">
                 <font size="12"/>
            </textElement>
           <textFieldExpression><![CDATA[$F{schooldetails_Phone}]]>  
           </textFieldExpression>
             </textField>
            </jr:detailCell>
          </jr:column>
Diaphane answered 20/3, 2013 at 5:10 Comment(2)
sorry.. tried your suggestion.. but still the table is displayed two times.. any other solutions ?Leighton
Use your original report and copy the table component in summary band and delete the detail bandDiaphane
W
0

If your table shows multiple times within List component, uncheck "Print when Detail Overflow" and try. It works for me.

Withdrew answered 22/1, 2019 at 6:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.