I'm using the iReport with to display data from a net.sf.jasperreports.engine.data.JRTableModelDataSource
in a table. I'm using the TableModelDataSource, because I have to use Java as a data source.
I now got the following code, which is working fine:
<?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="controltest" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.3310000000000022"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="276"/>
<property name="ireport.callouts" value="##Wed Dec 05 08:22:05 CET 2012"/>
<subDataset name="plantsResultTable">
<field name="COLUMN_0" class="java.lang.String"/>
<field name="COLUMN_1" class="java.lang.String"/>
<field name="COLUMN_2" class="java.lang.String"/>
<field name="COLUMN_3" class="java.lang.String"/>
<field name="COLUMN_4" class="java.lang.String"/>
<field name="COLUMN_5" class="java.lang.String"/>
<field name="readActualSupply" class="java.lang.String"/>
<group name="supplyGroup">
<groupExpression><![CDATA[$F{readActualSupply}]]></groupExpression>
</group>
</subDataset>
<field name="remotelyControlledSupply" class="java.lang.String"/>
<field name="thirdPartyAccess" class="java.lang.String"/>
<field name="plantsResultTable" class="net.sf.jasperreports.engine.JRDataSource"/>
<background>
<band/>
</background>
<pageHeader>
<band/>
</pageHeader>
<detail>
<band height="675">
<frame>
<reportElement x="0" y="250" width="555" height="239"/>
<componentElement>
<reportElement key="table 2" x="0" y="17" width="555" height="222"/>
<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="plantsResultTable">
<dataSourceExpression><![CDATA[$F{plantsResultTable}]]></dataSourceExpression>
</datasetRun>
<jr:column width="90">
<jr:columnHeader height="30">
<staticText>
<reportElement x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[COLUMN_0]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20">
<textField pattern="">
<reportElement x="0" y="0" width="90" height="20">
<printWhenExpression><![CDATA[$V{supplyGroup_COUNT} == 1]]></printWhenExpression>
</reportElement>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{COLUMN_0}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90">
<jr:columnHeader height="30">
<staticText>
<reportElement x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[COLUMN_1]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20">
<textField>
<reportElement x="0" y="0" width="90" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{COLUMN_1}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90">
<jr:columnHeader height="30">
<staticText>
<reportElement x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[COLUMN_2]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20">
<textField>
<reportElement x="0" y="0" width="90" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{COLUMN_2}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90">
<jr:columnHeader height="30">
<staticText>
<reportElement x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[COLUMN_3]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20">
<textField>
<reportElement x="0" y="0" width="90" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{COLUMN_3}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90">
<jr:columnHeader height="30">
<staticText>
<reportElement x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[COLUMN_4]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20">
<textField>
<reportElement x="0" y="0" width="90" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{COLUMN_4}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90">
<jr:columnHeader height="30">
<staticText>
<reportElement x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[COLUMN_5]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20">
<textField>
<reportElement x="0" y="0" width="90" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{COLUMN_5}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</frame>
</band>
</detail>
<columnFooter>
<band/>
</columnFooter>
<pageFooter>
<band/>
</pageFooter>
<summary>
<band/>
</summary>
</jasperReport>
What I need to know now is
- Is there a way to center the COLUMN_0 value vertically (set vertical alignment to "center"). I guess it's got to go by sth like
if $V{supplyGroup_COUNT} == $V{supplyGroup_SIZE}/2
. I have the table shown under "actual", but I want it dynamically to look like "target". - Is there a way to print another COLUMN_0 value if the table has a page break. That is the table begins on page 1 and breaks onto page 2 ending there. Can I print a COLUMN_0 value on page 1 and on page 2? I put an
<printWhenExpression><![CDATA[$V{supplyGroup_COUNT} == 1 || $P{hasPageBreak}.equals("1"))]]></printWhenExpression>
to my table's textField, but the compiler complains about not being able to find the parameter hasPageBreak. At the moment I just count the items in my table and put another "text" visible if $V{supplyGroup_COUNT} == 20 and if there is a new page.
3. Is there a way to force a table to break after a certain amount of items? I have some text that follows the table. I'd like to always have at least a part (the end) of the table together with the following text. Or do I have to use two separate tables?