2

I have a probably simple problem when using ireport table component. I'm using XML as the datasource for the report.

The problem is that the table never shows the first entry of the dataset associated with it. Imagine I have this data:

<name>
   <first>adam 1</first>
   <last>sand 1</last>          
</name> 
<name>
   <first>adam 2</first>
   <last>sand 2</last>          
</name> 
<name>
   <first>adam 3</first>
   <last>sand 3</last>          
</name> 

The output (table) will be (all data except the first row):

first last
adam 2 sand 2
adam 3 sand 3

The report template:

<?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="consumption_in_zones_data" pageWidth="500" pageHeight="802" columnWidth="500" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <property name="ireport.layers" value="##Tue Dec 06 12:01:43 GMT 2011\nlayer.0.name=Background\nlayer.0.visible=true\nlayer.0.id=0"/>
    <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="#999999">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFCC">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </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>
    </style>
    <subDataset name="table dataset">
        <parameter name="ZoneID" class="java.lang.String"/>
        <parameter name="PERIOD" class="java.lang.String"/>
        <parameter name="UNIT" class="java.lang.String"/>
        <queryString language="xPath">
            <![CDATA[/OrganizationData/Building/Zone/Indicator/ActiveEnergy[ZoneID='$P{ZoneID}']]]>
        </queryString>
        <field name="time" class="java.lang.String">
            <fieldDescription><![CDATA[time]]></fieldDescription>
        </field>
        <field name="consumption" class="java.lang.Double">
            <fieldDescription><![CDATA[consumption]]></fieldDescription>
        </field>
    </subDataset>
    <parameter name="ZoneID" class="java.lang.String"/>
    <parameter name="PERIOD" class="java.lang.String"/>
    <parameter name="UNIT" class="java.lang.String"/>
    <queryString language="xPath">
        <![CDATA[/OrganizationData/Building/Zone/Indicator/ActiveEnergy[ZoneID='$P{ZoneID}']]]>
    </queryString>
    <field name="time" class="java.lang.String">
        <fieldDescription><![CDATA[time]]></fieldDescription>
    </field>
    <field name="consumption" class="java.lang.Double">
        <fieldDescription><![CDATA[consumption]]></fieldDescription>
    </field>
    <variable name="consumption_1" class="java.lang.Double" resetType="Column" calculation="Sum">
        <variableExpression><![CDATA[$F{consumption}]]></variableExpression>
    </variable>
    <variable name="consumption_2" class="java.lang.Double" resetType="Column" calculation="Sum">
        <variableExpression><![CDATA[$F{consumption}]]></variableExpression>
    </variable>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="197" splitType="Stretch">
            <componentElement>
                <reportElement key="table 1" style="table 1" x="0" y="0" width="500" height="197"/>
                <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="table dataset">
                        <datasetParameter name="ZoneID">
                            <datasetParameterExpression><![CDATA[$P{ZoneID}]]></datasetParameterExpression>
                        </datasetParameter>
                        <datasetParameter name="PERIOD">
                            <datasetParameterExpression><![CDATA[$P{PERIOD}]]></datasetParameterExpression>
                        </datasetParameter>
                        <datasetParameter name="UNIT">
                            <datasetParameterExpression><![CDATA[$P{UNIT}]]></datasetParameterExpression>
                        </datasetParameter>
                        <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="90">
                        <jr:tableHeader style="table 1_TH" height="30" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="30"/>
                                <textElement textAlignment="Center"/>
                                <textFieldExpression><![CDATA[$P{PERIOD}]]></textFieldExpression>
                            </textField>
                        </jr:tableHeader>
                        <jr:detailCell style="table 1_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement textAlignment="Center"/>
                                <textFieldExpression><![CDATA[$F{time}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:tableHeader style="table 1_TH" height="30" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="30"/>
                                <textElement textAlignment="Center"/>
                                <textFieldExpression><![CDATA[$P{UNIT}]]></textFieldExpression>
                            </textField>
                        </jr:tableHeader>
                        <jr:detailCell style="table 1_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement textAlignment="Center"/>
                                <textFieldExpression><![CDATA[$F{consumption}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
</jasperReport>

Data snippet:

<OrganizationData>
  <Building>
    <BuildingID>71721890-efd1-012c-c545-0a48cbee2b22</BuildingID>
    <BuildingName>PT</BuildingName>
    <Tariff>low</Tariff>
    <Zone>
      <ZoneID>bceba570-d0e2-012e-d950-7ac0bc5389eb</ZoneID>
      <BuildingID>71721890-efd1-012c-c545-0a48cbee2b22</BuildingID>
      <ZoneName>PT - Zone A</ZoneName>
      <Type>ROUT</Type>
      <Indicator>
        <IndicatorID>96a41e20-60d8-012d-516c-5aacf9dbb012</IndicatorID>
        <ZoneID>bceba570-d0e2-012e-d950-7ac0bc5389eb</ZoneID>
        <BuildingID>71721890-efd1-012c-c545-0a48cbee2b22</BuildingID>
        <IndicatorName>EA+ BlA P0</IndicatorName>
        <ActiveEnergy>
          <IndicatorID>96a41e20-60d8-012d-516c-5aacf9dbb012</IndicatorID>
          <ZoneID>bceba570-d0e2-012e-d950-7ac0bc5389eb</ZoneID>
          <BuildingID>71721890-efd1-012c-c545-0a48cbee2b22</BuildingID>
          <time>01 Oct</time>
          <consumption>0.1</consumption>
        </ActiveEnergy>
        <ActiveEnergy>
          <IndicatorID>96a41e20-60d8-012d-516c-5aacf9dbb012</IndicatorID>
          <ZoneID>bceba570-d0e2-012e-d950-7ac0bc5389eb</ZoneID>
          <BuildingID>71721890-efd1-012c-c545-0a48cbee2b22</BuildingID>
          <time>02 Oct</time>
          <consumption>0.1</consumption>
        </ActiveEnergy>
      </Indicator>
    </Zone>
  </Building>
</OrganizationData>

thanks in advance, Nuno

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
nunopato
  • 55
  • 3
  • 10

1 Answers1

3

I've just check the table element with this test case.

My template:

<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="tablesample2" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <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>
    </style>
    <subDataset name="Table Dataset 1">
        <field name="city" class="java.lang.String"/>
        <field name="id" class="java.lang.String"/>
    </subDataset>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="city" class="java.lang.String"/>
    <field name="id" class="java.lang.String"/>
    <detail>
        <band height="80" splitType="Stretch">
            <componentElement>
                <reportElement key="table" style="table" x="100" y="0" width="270" height="80"/>
                <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="Table Dataset 1">
                        <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="90">
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$F{city}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:detailCell style="table_TD" height="20" rowSpan="1"/>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
</jasperReport>

My csv data file was:

"Dallas",47,"Janet Fuller","445 Upland Pl.","Trial"
"Lyon",38,"Andrew Heiniger","347 College Av.","Active"
"Dallas",43,"Susanne Smith","2 Upland Pl.","Active"
"Berne",22,"Bill Ott","250 - 20th Ave.","Active"
"Boston",32,"Michael Ott","339 College Av.","Trial"
"Dallas",4,"Sylvia Ringer","365 College Av.","Active"
"Boston",23,"Julia Heiniger","358 College Av.","Active"
"Chicago",39,"Mary Karsen","202 College Av.","Active"
"Dallas",40,"Susanne Miller","440 - 20th Ave.","Trial"
"Berne",9,"James Schneider","277 Seventh Av.","Active"
"Dallas",36,"John Steel","276 Upland Pl.","Suspended"
"Chicago",35,"George Karsen","412 College Av.","Suspended"
"Dallas",37,"Michael Clancy","19 Seventh Av.","Deleted"
"Lyon",2,"Anne Miller","20 Upland Pl.","Active"
"Dallas",0,"Laura Steel","429 Seventh Av.","Active"
"Lyon",28,"Susanne White","74 - 20th Ave.","Deleted"
"Paris",5,"Laura Miller","294 Seventh Av.","Active"
"Lyon",17,"Laura Ott","443 Seventh Av.","Active"
"New York",46,"Andrew May","172 Seventh Av.","Active"
"New York",44,"Sylvia Ott","361 College Av.","Active"
"Dallas",19,"Susanne Heiniger","86 - 20th Ave.","Active"
"Chicago",11,"Julia White","412 Upland Pl.","Active"
"Dallas",10,"Anne Fuller","135 Upland Pl.","Active"
"New York",41,"Bill King","546 College Av.","Deleted"
"Oslo",45,"Janet May","396 Seventh Av.","Active"
"Paris",18,"Sylvia Fuller","158 - 20th Ave.","Trial"
"San Francisco",48,"Robert White","549 Seventh Av.","Active"
"Paris",25,"Sylvia Steel","269 College Av.","Suspended"
"San Francisco",7,"James Peterson","231 Upland Pl.","Active"
"Oslo",42,"Robert Ott","503 Seventh Av.","Trial"

The first row from the data source was missed in the table.

I think this is issue related with iteration over the main datasource. You can read
Why is the first record missing from my subreport?
post on community.jaspersoft.com.

Alex K
  • 22,315
  • 19
  • 108
  • 236
  • First thanks for your reply. I cannot remove the ZoneID from the query because this report is actually a subreport that receives a ZoneID to filtrate the energy associated with it. If i remove it, the table shows all energy for all zones of that building (curiously not showing the first row AGAIN). Thanks – nunopato Dec 07 '11 at 15:04
  • Can you post the data file that has more information that mine? I'll try it again – Alex K Dec 07 '11 at 15:15
  • I've got only the data for `ZoneID` that equals to parameter. Is it wrong? It was first three `ActiveEnergy` from my data file. – Alex K Dec 07 '11 at 15:16
  • Yes it is right for you. Are you using the table component? If i just put the fields in the detail band, it prints all of them for the correct ZoneID. My problem is using the table component. – nunopato Dec 07 '11 at 15:25
  • Yes, I've used your jrxml file with my data file – Alex K Dec 07 '11 at 15:28
  • Very weird. I've tested now with your data example and the same result. Just 2 rows... – nunopato Dec 07 '11 at 15:35
  • What version of iReport are you using? – nunopato Dec 07 '11 at 15:36
  • The same as you - 4.1.3. Did you recompile report (after the editting the main query)? – Alex K Dec 07 '11 at 15:37
  • Yes..are you filtering the ZoneID in the main query or in the dataset query associated with the table? – nunopato Dec 07 '11 at 15:43
  • In my sample - only by table's query – Alex K Dec 07 '11 at 15:43
  • I just don't get it. Is your main query empty? Thanks for averything – nunopato Dec 07 '11 at 15:50
  • Solved!!! I was filtering ZoneID in the main query. I don't know why, but there is a subtle difference. Thank you very much. – nunopato Dec 07 '11 at 15:56
  • Oopps, sorry - just found in my output, the data is wrong. 3 rows but not the correct – Alex K Dec 07 '11 at 15:56
  • Wrong again! Testing with the main report and the subreport together because i don't filter the ZoneID at the subreport main query...the table is printed with all energy data for all zones... – nunopato Dec 07 '11 at 16:04
  • I'll try it again. My main thought is to leave only one query - in the table's data source. – Alex K Dec 07 '11 at 16:06
  • Your data file is wrong. You have two different ZoneID's in the same . – nunopato Dec 07 '11 at 16:25
  • Ok, I will try with your data. But you should correct it - it is not well-formed XML – Alex K Dec 07 '11 at 16:37