Jasper Report: CSV DataSource in table component - jasper-reports

I have a requirement where I have to read CSV file and prepare a report in Jasper. I am able to use CSV data source in regular text field. But when I add a table to Detail or Summary section it expects a new Data Set to be created. I created it successfully but when the report runs it is not able to get the data from CSV data source, I am getting a blank report. The same thing works if I use Database instead of CSV. Is there a bug in Jasper.

I had the same problem. To fix it, go to the table component, right-click, then "Edit data source", choice "Connection data source expression" and write:
((net.sf.jasperreports.engine.data.JRCsvDataSource)$P{REPORT_DATA_SOURCE})

Below is a sample JRXML which shows how to use a CSV data source in the table component.
Please note that you need to name the fields in the sub dataset "COLUMN_" + the column index. This way in JRCsvDataSource#getFieldValue your field will be located correctly without having to add a row for column headers in the CSV file.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.0.final using JasperReports Library version 6.3.0 -->
<!-- 2016-08-23T13:06:06 -->
<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="SimpleReportWithTable" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="b32b572d-c517-48ba-a44e-3402966e9932">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="SimpleCsvDataAdapter"/>
<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="#BFE1FF">
<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="#FBFDFF"/>
</conditionalStyle>
</style>
<subDataset name="Dataset1" uuid="76efa803-c263-4538-a39a-8ddb1712e58a">
<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="COLUMN_6" class="java.lang.String"/>
<field name="COLUMN_7" class="java.lang.String"/>
<field name="COLUMN_8" class="java.lang.String"/>
</subDataset>
<parameter name="CSV_DATA_SOURCE" class="net.sf.jasperreports.engine.data.JRCsvDataSource" isForPrompting="false">
<defaultValueExpression><![CDATA[new net.sf.jasperreports.engine.data.JRCsvDataSource("path_to_csv_file")]]></defaultValueExpression>
</parameter>
<summary>
<band height="70" splitType="Stretch">
<componentElement>
<reportElement x="0" y="10" width="200" height="60" uuid="a5c67e1f-1b96-4044-b4d2-ba9da8502bab">
<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"/>
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
</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" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="Dataset1" uuid="7738bf3c-ecda-4864-9804-c6319de53296">
<dataSourceExpression><![CDATA[$P{CSV_DATA_SOURCE}]]></dataSourceExpression>
</datasetRun>
<jr:column width="66" uuid="5c06dacd-68b4-4972-87e9-45dcbf181cbd">
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="66" height="30" uuid="3ecb3cf8-02f5-4783-b407-9d36a3b76a9e"/>
<text><![CDATA[Row 1]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="66" height="30" uuid="21db9e1b-c129-40f6-afd5-c8fc9b939112"/>
<textFieldExpression><![CDATA[$F{COLUMN_0}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="66" uuid="45989e75-9ad1-4a48-ae63-ddaf380930e7">
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="66" height="30" uuid="392ead1f-fd67-431c-8da6-3cf3dad9728d"/>
<text><![CDATA[Row 2]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="66" height="30" uuid="1a1fb7ba-cec2-44f7-bdc7-3a3887302fb0"/>
<textFieldExpression><![CDATA[$F{COLUMN_1}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="66" uuid="128a9867-c221-4862-a9ac-f5cc99e394f1">
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="66" height="30" uuid="033b57f1-b3dd-4909-8ed7-84c99f92eccd"/>
<text><![CDATA[Row 3]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="66" height="30" uuid="0d2027c4-e761-4e14-b093-31be3c0493e0"/>
<textFieldExpression><![CDATA[$F{COLUMN_2}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</summary>
</jasperReport>

For table component you have to create new data source, What you have to do drag a table component and click on "New Dataset" and select CSV dataset from the connection/Data Sources drop down list.

Related

use Table dataset field value in main report

<?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="TestingImage" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="5470e3fc-1c9c-4841-8814-e3a935fa6684"> <property name="ireport.zoom" value="1.0"/><property name="ireport.x" value="0"/><property name="ireport.y" value="229"/><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><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="#BFE1FF"><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>
</style>
<subDataset name="ImageDemoDataset" uuid="47414685-b792-4a30-9b14-fc32127ad3cc">
<parameter name="lastname" class="java.lang.String">
<defaultValueExpression><![CDATA[$F{picture}]]></defaultValueExpression>
</parameter>
<parameter name="firstname" class="java.lang.String">
<defaultValueExpression><![CDATA[$F{firstname}]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<field name="firstname" class="java.lang.String"/>
<field name="lastname" class="java.lang.String"/>
<field name="email" class="java.lang.String"/>
<field name="phone_number" class="java.lang.String"/>
<field name="picture" class="java.lang.String"/>
<variable name="imagePath" class="java.lang.String" resetType="None">
<variableExpression><![CDATA[$F{picture}]]></variableExpression>
</variable>
</subDataset>
<parameter name="ImageDataSource" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<queryString>
<![CDATA[]]>
</queryString>
<variable name="varImage" class="java.lang.String" resetType="None"/>
<detail>
<band height="364" splitType="Stretch">
<componentElement>
<reportElement x="18" y="0" width="474" height="216" uuid="771aa5d8-1470-4fd9-b062-a913b6014f19">
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
</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" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="ImageDemoDataset" uuid="c4a063af-d8d1-41c4-98bf-660a9eab651e">
<dataSourceExpression><![CDATA[$P{ImageDataSource}]]></dataSourceExpression>
<returnValue fromVariable="imagePath" toVariable="varImage"/>
</datasetRun>
<jr:column width="70" uuid="6aa96500-79ab-4b8b-aa5f-0c9dbc22638f">
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="70" height="30" uuid="9528bbd1-627c-424c-a3f0-872f92799c94"/>
<textFieldExpression><![CDATA[$F{firstname}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="ba88fb55-d423-4d1e-99a1-b81c44f6e65a">
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="90" height="30" uuid="5c85fd56-54ba-4d22-a3e4-adcdbbbc2b4f"/>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{lastname} ]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="100" uuid="29524685-b68a-4906-be22-50b0acacba7d">
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="9dacce68-21ca-4bcc-b9cb-bad1b3661611"/>
<textFieldExpression><![CDATA[$F{email}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="94" uuid="4bb9635f-4173-4c5b-95ce-5a12a2332ea1">
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="94" height="30" uuid="8c6c58b1-d3fd-4fad-995a-caaaea6afe8e"/>
<textFieldExpression><![CDATA[$F{phone_number}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="100" uuid="b500de9f-6abf-41b8-9e5d-d408b94d32ce">
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="0e6a1e56-974f-41a3-af08-0cf5b832b573"/>
<textFieldExpression><![CDATA[$F{picture}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
<image scaleImage="FillFrame" hAlign="Center" vAlign="Middle">
<reportElement x="48" y="266" width="100" height="98" uuid="290e1eb9-3a18-4a65-93d4-d155b98ce964">
<printWhenExpression><![CDATA[!$V{varImage}.equalsIgnoreCase("null")]]></printWhenExpression>
</reportElement>
<imageExpression><![CDATA["C:\\Users\\jigpra\\Pictures\\"+$V{varImage}]]></imageExpression>
</image>
<staticText>
<reportElement x="48" y="231" width="100" height="20" uuid="32fd136d-d7c4-4256-be6c-e9ad7d5f7592"/>
<textElement>
<font size="12"/>
</textElement>
<text><![CDATA[$V{varImage}]]></text>
</staticText>
</band>
</detail>
I want to use Table dataset Field/parameter in Main report. I added data of collection in table to show upin this data I have one value is image for every column. I want to get that Image name (currently in collection dataset I pass name of image).
How can I retrieve picture field name in main report?
You do not see the image because it does not have the proper Evaluation Time - it needs to be Band in your case.
The staticText does not support such setting, you need to convert it to a textField and set the same for the Evaluation Time property.
But even with the above suggestions you would still see the last value from your ImageDemoDataset subDataset. It is fine if that is what you want.
But if you want to display an image for each record in your subDataset, you would have to do it inside the table. If spacing was the issue, you could create a columnGroup and place the image in the groupFooter, isolating it below your main data.
EDIT: It seems that what you want is actually simpler and should not involve variables. You just need to reiterate over the same data source.
This can be done in 2 ways:
(1). Using the original ImageDataSource parameter:
<parameter name="ImageDataSource" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
have the table datasetRun's expression like so:
<dataSourceExpression><![CDATA[$P{ImageDataSource}.cloneDataSource()]]></dataSourceExpression>
Then create a list component under the table, with the same subDataset you used for the table and the initial data source expression:
<dataSourceExpression><![CDATA[$P{ImageDataSource}]]></dataSourceExpression>
and set its Print Order to Horizontal in the List tab from the list component properties. Make sure you also specify the Cell Width to be small enough to allow repeating items to flow horizontally.
Cloning the dataSource for the table will ensure that the table will not exhaust it, so that the list component will still be able to iterate over it.
(2). Instead of passing the JRBeanCollectionDataSource as a parameter, pass just the collection you created it with and have a parameter for that. This way you do not need to clone the dataSource anymore:
<parameter name="ImageCollection" class="java.util.Collection"/>
Then have the table datasetRun's expression like so:
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{ImageCollection})]]></dataSourceExpression>
Then create a list with the same subDataset you used for the table and use the dataSourceExpression from above. You should set up the list in the same way as in (1).

Jasper - first page in blank

I'm inserting a table in my detail band, but if the value is too long in my textfield, the value is showed only in the second page and because of this the first page is blank.
How I can avoid empty first page on Ireport?
Below is my XML 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="RelatorioLicenca" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="089efa24-5b40-467a-b66a-053b77756f0c">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<style name="table">
<box>
<pen lineWidth="0.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="dataset1" uuid="7664203f-829d-4951-8151-f0c3630108d3"/>
<subDataset name="dataset2" uuid="b05d44f7-3dfe-4fb8-9014-34c037e8bc28"/>
<subDataset name="dataset3" uuid="f3336d08-b905-45da-9cd2-871a08fbb704"/>
<subDataset name="dataset4" uuid="8a31051f-53a0-4438-8f36-655294512ecb"/>
<subDataset name="itemDataSet" uuid="07d68903-44a5-4148-9f4e-46a764459558">
<field name="html" class="java.lang.String"/>
</subDataset>
<parameter name="LOGO_IMAGE" class="java.io.InputStream"/>
<parameter name="BARRA_IMAGE" class="java.io.InputStream"/>
<parameter name="listCriterioQci" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="73" splitType="Stretch">
<image>
<reportElement x="137" y="2" width="284" height="54" uuid="07b821b9-797c-439c-92e8-1963c63ee2ae"/>
<imageExpression><![CDATA[$P{LOGO_IMAGE}]]></imageExpression>
</image>
<image>
<reportElement x="0" y="59" width="555" height="14" uuid="4b071978-b491-4bdb-b964-77cc3e378966"/>
<imageExpression><![CDATA[$P{BARRA_IMAGE}]]></imageExpression>
</image>
</band>
</title>
<detail>
<band height="218" splitType="Stretch">
<componentElement>
<reportElement key="table" style="table" positionType="Float" isPrintRepeatedValues="false" mode="Opaque" x="2" y="8" width="553" height="197" isPrintWhenDetailOverflows="true" forecolor="#FFFFFF" uuid="086200b3-e8f8-454d-84ef-d91dbe233d92"/>
<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="itemDataSet" uuid="376ddebe-37e7-49e4-9a3c-c12cdb054808">
<dataSourceExpression><![CDATA[$P{listCriterioQci}]]></dataSourceExpression>
</datasetRun>
<jr:column width="554" uuid="cc022176-90eb-4639-8818-85293cb2da05">
<jr:detailCell style="table" height="135" rowSpan="1">
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" isPrintRepeatedValues="false" x="0" y="31" width="554" height="92" isPrintWhenDetailOverflows="true" uuid="75438790-5295-4508-b6fe-cae1b962ae1d"/>
<box>
<pen lineStyle="Solid" lineColor="#FFFFFF"/>
<topPen lineStyle="Solid" lineColor="#FFFFFF"/>
<leftPen lineStyle="Solid" lineColor="#FFFFFF"/>
<bottomPen lineStyle="Solid" lineColor="#FFFFFF"/>
<rightPen lineStyle="Solid" lineColor="#FFFFFF"/>
</box>
<textElement markup="html"/>
<textFieldExpression><![CDATA[$F{html}]]></textFieldExpression>
</textField>
<line>
<reportElement positionType="Float" x="0" y="15" width="554" height="1" uuid="7a8ae78a-41c3-4612-aeff-4aa9bbfe74f5">
<printWhenExpression><![CDATA[new Boolean($F{html} != null)]]></printWhenExpression>
</reportElement>
</line>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
<pageFooter>
<band height="21" splitType="Stretch">
<textField>
<reportElement mode="Opaque" x="342" y="4" width="170" height="13" uuid="26decbd6-15dd-4f66-99d7-132b5b54a889"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement mode="Opaque" x="514" y="4" width="40" height="13" uuid="e34184f8-e277-4ec3-9a69-0c07d0729e25"/>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement x="1" y="4" width="211" height="13" uuid="68ea646b-0cef-4427-86b7-32f0f5bd47f8"/>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band height="5" splitType="Stretch"/>
</summary>
</jasperReport>

How to format data in cells of crosstab using measures of different types

With regard to using crosstabs, is there a way to add any kind of formatting to the measures?
I have the data as follows.
I need to display col2, col4 as per the formatting specified for any geographical location. For example, in India, we show the date as 11/11/1986 and number as 1,00,000. Another country may show the data as 11.11.1986 and number as 1.00.000
How do I achieve this?
Also, while creating the crosstab, I do not add any calculated function to the crosstab, yet, it takes up the highest values for that combination of row group and column group. Why is this? Here is the picture of the same
And the jrxml for the same is as below
<?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="crosstabmeasure" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="e47b3f7d-1e00-4702-a900-be50a229f085">
<style name="Crosstab_CH" 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="Crosstab_CG" mode="Opaque" backcolor="#BFE1FF">
<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="Crosstab_CT" mode="Opaque" backcolor="#005FB3">
<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="Crosstab_CD" 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>
</style>
<parameter name="Locale" class="java.lang.String">
<defaultValueExpression><![CDATA["en-IN"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[select * from internatioinlization]]>
</queryString>
<field name="col1" class="java.lang.String"/>
<field name="col2" class="java.lang.Integer"/>
<field name="col3" class="java.sql.Timestamp"/>
<field name="col4" class="java.lang.String"/>
<summary>
<band height="211" splitType="Stretch">
<crosstab>
<reportElement x="0" y="0" width="555" height="211" uuid="6c5ccb8a-50fc-4158-b2ba-88d864aa1e43"/>
<rowGroup name="col11" width="60">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{col1}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="60" height="20" uuid="86c09a7f-46b5-4d2f-ba87-715f99d832a8"/>
<textFieldExpression><![CDATA[$V{col11}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents>
<staticText>
<reportElement x="0" y="0" width="-2147483648" height="-2147483648" uuid="94fca0ea-1572-4d42-85d9-b06f92c73b6e"/>
<text><![CDATA[Total col11]]></text>
</staticText>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="col41" height="20">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{col4}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<textField>
<reportElement x="0" y="0" width="120" height="20" uuid="137ef406-6a2e-4629-9d38-4858c4a5ae2c">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textFieldExpression><![CDATA[$V{col41}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents>
<staticText>
<reportElement x="0" y="0" width="-2147483648" height="-2147483648" uuid="5c71211d-f1db-4911-8923-2bdb208ddb99"/>
<text><![CDATA[Total col41]]></text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="col2_MEASURE1" class="java.lang.Integer">
<measureExpression><![CDATA[$F{col2}]]></measureExpression>
</measure>
<measure name="col3_MEASURE1" class="java.sql.Timestamp">
<measureExpression><![CDATA[$F{col3}]]></measureExpression>
</measure>
<crosstabCell width="120" height="20">
<cellContents mode="Opaque" style="Crosstab_CD">
<textField>
<reportElement x="0" y="0" width="60" height="20" uuid="861d0d3a-d774-4b0c-ae7d-ace315bf305c"/>
<textFieldExpression><![CDATA[$V{col2_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="60" y="0" width="60" height="20" uuid="163ed502-e753-444a-942d-832d84da0a5f">
</reportElement>
<textFieldExpression><![CDATA[$V{col3_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" columnTotalGroup="col41">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="2576b9e2-3bba-40e3-aa15-5f4f0aada549"/>
<textFieldExpression><![CDATA[$V{col2_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="a111181f-b60f-4afd-8292-9e260c1b9ce2"/>
<textFieldExpression><![CDATA[$V{col3_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="col11">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="9adf6c9c-acee-4673-8b70-a376e7d1cbb4"/>
<textFieldExpression><![CDATA[$V{col2_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="9baedeed-4770-4153-b639-afc0965e9467"/>
<textFieldExpression><![CDATA[$V{col3_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="col11" columnTotalGroup="col41">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="a2805e0a-080d-42be-ad86-a7e8e666f571"/>
<textFieldExpression><![CDATA[$V{col2_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="c485f69d-91e1-4b19-a8ab-bdbfa3cafcc6"/>
<textFieldExpression><![CDATA[$V{col3_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</summary>
</jasperReport>
It is better to stay measureExpression AS IS and apply formatting for textFieldExpression.
The textFieldExpression in crosstab can operate with crosstab's parameters values.
If the main Main dataset is using at crosstab we can use the
crosstab's parameters in cells of crosstab.
If the another dataset
is using at crosstab we can this dataset's parameters in cells of
crosstab.
Example
Datasource
The csv datasource is using in example.
col1,col2,col3,col4
a,a123,10,12/02/2016
a,a123,20,30/01/2016
a,a123,44,21/01/2016
a,b456,5,28/03/2016
b,a123,15,23/03/2015
b,b456,100,13/05/2015
b,b456,200,10/09/2015
b,b456,130,09/09/2017
The name of data adapter for this datasource in the example below is values.csv. The first line from the file is skipped - it is contains the column's name.
Report template
Col1 is using in rowGroups, col2 is using at columnGroups.
With help of measureExpression the crosstab showing the Sum of col3 for each group and the Highest date (col4).
The formatting will be applied for textFields. The parameter will be used for Date formatting.
In this example the Main dataset is using for showing data at crosstab. We need to pass the value of report's parameter to the crosstab's parameters, because we can't use report's parameters in crosstab (with rare exceptions).
<crosstabParameter name="dateFormat" class="java.text.SimpleDateFormat">
<parameterValueExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}.get("SIMPLE_DATE_FORMAT")]]></parameterValueExpression>
</crosstabParameter>
- this is initialization of crosstab's parameter (dateFormat) with help of REPORT_PARAMETERS_MAP report's parameter. The value of REPORT_PARAMETERS_MAP parameter can be accessed from crosstab.
The value of report's parameter SIMPLE_DATE_FORMAT can be passed to the report for example with help of Java code.
The jrxml code:
<?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="Formatted measures" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="values.csv"/>
<style name="Crosstab_CH" 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="Crosstab_CD" 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>
</style>
<parameter name="SIMPLE_DATE_FORMAT" class="java.text.SimpleDateFormat" isForPrompting="false">
<defaultValueExpression><![CDATA[new java.text.SimpleDateFormat("dd.MM.yyyy")]]></defaultValueExpression>
</parameter>
<field name="col1" class="java.lang.String"/>
<field name="col2" class="java.lang.String"/>
<field name="col3" class="java.lang.Integer"/>
<field name="col4" class="java.util.Date"/>
<summary>
<band height="270">
<crosstab>
<reportElement x="20" y="70" width="525" height="200" >
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
</reportElement>
<crosstabParameter name="dateFormat" class="java.text.SimpleDateFormat">
<parameterValueExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}.get("SIMPLE_DATE_FORMAT")]]></parameterValueExpression>
</crosstabParameter>
<rowGroup name="col1" width="60">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{col1}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="60" height="20"/>
<textFieldExpression><![CDATA[$V{col1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
</rowGroup>
<columnGroup name="col2" height="20">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{col2}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="180" height="20"/>
<textFieldExpression><![CDATA[$V{col2}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
</columnGroup>
<measure name="col3_MEASURE" class="java.lang.Integer" calculation="Sum">
<measureExpression><![CDATA[$F{col3}]]></measureExpression>
</measure>
<measure name="col4_MEASURE" class="java.util.Date" calculation="Highest">
<measureExpression><![CDATA[$F{col4}]]></measureExpression>
</measure>
<crosstabCell width="180" height="40">
<cellContents mode="Opaque" style="Crosstab_CD">
<textField pattern="#,##0.00">
<reportElement x="0" y="0" width="180" height="20"/>
<textFieldExpression><![CDATA[$V{col3_MEASURE}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="20" width="180" height="20"/>
<textFieldExpression><![CDATA[$V{col2}.equals("a123") ? $P{dateFormat}.format($V{col4_MEASURE}) :
new SimpleDateFormat("dd/MM/yy").format($V{col4_MEASURE})]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</summary>
</jasperReport>
The expression for showing data can be complex as in this example. With help of expression:
<textFieldExpression><![CDATA[$V{col2}.equals("a123") ? $P{dateFormat}.format($V{col4_MEASURE}) :
new SimpleDateFormat("dd/MM/yy").format($V{col4_MEASURE})]]></textFieldExpression>
we are showing dates in different formats for different columns (col2).
Output result
The result in Jaspersoft Studio will be:
The sum of Integer values formatted with help of pattern attribute and the max value of Date values formatted with help of Java expression.

Multiple rows inside a single column in jasper table

I am just a beginner in jasper report and i am stuck for a few days in a problem.
I have two tables
Medication {ID,medication_name}
and
dose_time{ID,medication_id,dose_time}
Applying
SELECT m.id,m.medication_name,d_t.dose_time FROM medication `m`
LEFT JOIN dose_time d_t ON m.id=d_t.medication_id;
gives me three result
Now what i want is following jasper report
But i could stuck and can generate only following jasper format
My jrxml file is as follow
<?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="PracticeReport" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="67dfb372-a5be-403b-9007-61ab07fe88e7">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<subDataset name="Medication" uuid="1cccb880-701b-491e-8094-c133d4bd3819">
<queryString>
<![CDATA[SELECT m.id,m.medication_name,d_t.dose_time FROM medication `m`
LEFT JOIN dose_time d_t ON m.id=d_t.medication_id;]]>
</queryString>
<field name="id" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="medication_name" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="dose_time" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<group name="id">
<groupExpression><![CDATA[$F{id}]]></groupExpression>
</group>
</subDataset>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement uuid="8bc54002-3e51-4bd6-8801-9856ef627b99" x="154" y="28" width="240" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Practicing Jasper]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<componentElement>
<reportElement uuid="5976a679-e65a-4880-a9e7-74fd65f9e80d" key="" isPrintRepeatedValues="false" x="0" y="0" width="555" height="125">
<printWhenExpression><![CDATA[$V{REPORT_COUNT}==1]]></printWhenExpression>
</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" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="Medication" uuid="5f6c54e4-9c5c-4120-8ac7-32793ec39d00"/>
<jr:column width="232" uuid="c5a6dca0-3be4-422f-8f13-4462d2e4caee">
<jr:detailCell height="124" rowSpan="1">
<textField>
<reportElement uuid="080e50f3-23a0-4bf2-8d6f-b63618dfdc51" isPrintRepeatedValues="false" x="0" y="0" width="232" height="124"/>
<box>
<pen lineWidth="0.75"/>
<topPen lineWidth="0.75"/>
<leftPen lineWidth="0.75"/>
<bottomPen lineWidth="0.75"/>
<rightPen lineWidth="0.75"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{id} + ","+$F{medication_name}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="232" uuid="b7bef864-31db-4b77-a929-a0d59e754b36">
<jr:detailCell height="124" rowSpan="1">
<textField>
<reportElement uuid="7b3c68b6-6048-4690-b8e7-14a286f94297" x="0" y="0" width="232" height="124"/>
<box>
<pen lineWidth="0.75"/>
<topPen lineWidth="0.75"/>
<leftPen lineWidth="0.75"/>
<bottomPen lineWidth="0.75"/>
<rightPen lineWidth="0.75"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{dose_time}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
Please guys i need your help.
You can use a crosstab for that. Go to Window and click on Palette. Than the palette will appear right. Finally, drag 'crosstab' to the summary section and fill in the wizard.
This might be of some help https://community.jaspersoft.com/wiki/how-merge-table-rows-repeated-values
In this solution, 2 datasets are used, the first dataset groups the data while the second dataset is used to create a table which is embedded in a band.
Edit: I applied another approach to do this. I used a table for the entire thing. The first column of the table is for the medicine and contains a textfield. The second column of the table is for the timing. It is a sub report and the sub report in turn contains another table with the timing.
I didn't use SQL but created a manual data in java. Here is my java code.
import static com.vroozi.api.requests.util.JasperUtils.compileJrxmlToJasper;
import com.vroozi.api.requests.util.JasperUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import org.springframework.stereotype.Service;
#Service
public class PDFServiceImpl {
public String generate() throws JRException {
final String format = DATE_TIME_FORMAT.format(new Date());
final String outputFileName = String.format("PO_%s_%s_PDF.pdf", "rajshree", format);
final String purchaseReportsPath = "/home/oem";
Map<String, Object> parameters = new HashMap<>();
Map<String, Object> cetamolMap = new HashMap<>();
cetamolMap.put("medicine", "Cetamol");
Map<String, Object> painKillerMap = new HashMap<>();
painKillerMap.put("medicine", "Pain killer");
List<Map<String, Object>> medicineMapList = Arrays.asList(cetamolMap, painKillerMap);
Map<String, Object> time1 = new HashMap<>();
time1.put("time", "11 a.m.");
Map<String, Object> time2 = new HashMap<>();
time2.put("time", "2 p.m.");
List<Map<String, Object>> timeMapList = Arrays.asList(time1, time2);
cetamolMap.put("timeList", new JRBeanCollectionDataSource(timeMapList));
painKillerMap.put("timeList", new JRBeanCollectionDataSource(new ArrayList<>()));
// Adding subreport for each medicine
cetamolMap.put("timeTableSubReport",
compileJrxmlToJasper("/subreport.jrxml"));
painKillerMap.put("timeTableSubReport",
compileJrxmlToJasper("/reports/subreport.jrxml"));
parameters.put("medicineMapList", new JRBeanCollectionDataSource(medicineMapList));
return JasperUtils.generatePdfReport("/reports/report.jrxml",
parameters, purchaseReportsPath, outputFileName);
}
}
Here is the "report.jrxml"
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<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="catalogPOCR" pageWidth="559" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="559" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" whenResourceMissingType="Empty" uuid="42c67c01-6232-438f-8149-de04399dfcd2">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="ireport.scriptlethandling" value="0"/>
<property name="ireport.encoding" value="UTF-8"/>
<import value="net.sf.jasperreports.engine.*"/>
<import value="org.apache.commons.collections.CollectionUtils"/>
<import value="java.util.*"/>
<import value="net.sf.jasperreports.engine.data.*"/>
<style name="table 1">
<box>
<pen lineWidth="0.0" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TH" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.0" lineColor="#000000"/>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</style>
<style name="table 1_CH" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.0" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.0" lineColor="#000000"/>
</box>
<conditionalStyle>
<conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
<style backcolor="#FFFFFF"/>
</conditionalStyle>
</style>
<subDataset name="Table LineItems" uuid="183918c2-b66e-4347-ae7b-e891ab0a1d88">
<field name="medicine" class="java.lang.String"/>
<field name="timeTableSubReport" class="net.sf.jasperreports.engine.JasperReport"/>
<field name="timeList" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
</subDataset>
<subDataset name="Dataset1" uuid="183918c2-b66e-4347-ae7b-e891ab0a1d88">
<field name="order" class="java.lang.String"/>
</subDataset>
<parameter name="medicineMapList" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<parameter name="timeTableSubReport" class="net.sf.jasperreports.engine.JasperReport" isForPrompting="false"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<detail>
<band height="170">
<componentElement>
<reportElement key="table 1" style="table 1" positionType="Float" x="0" y="0" width="504" height="70" uuid="eb4057df-dd6a-40dd-870e-baac8c8afe17">
<property name="local_mesure_unitwidth" value="inch"/>
<property name="com.jaspersoft.studio.unit.width" value="inch"/>
<printWhenExpression><![CDATA[$V{REPORT_COUNT} == 1]]></printWhenExpression>
</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="Table LineItems" uuid="8a44aec8-cdd4-4be3-b47a-620e00bb910a">
<datasetParameter name="REPORT_DATA_SOURCE">
<datasetParameterExpression><![CDATA[$P{medicineMapList}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
<jr:column width="70" uuid="baa7f786-d12a-4234-b9d7-faef6c9f25df">
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<box>
<pen lineWidth="0.0"/>
<topPen lineWidth="0.0"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="0.0"/>
<rightPen lineWidth="0.0"/>
</box>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="70" height="20" uuid="5f84b7ac-c2fe-4426-b91f-6714b470a2bc"/>
<box topPadding="5" leftPadding="2" bottomPadding="5" rightPadding="2">
<topPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="8" isBold="false"/>
<paragraph rightIndent="4"/>
</textElement>
<textFieldExpression><![CDATA[$F{medicine}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="70" uuid="baa7f786-d12a-4234-b9d7-faef6c9f25df">
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<box>
<pen lineWidth="0.0"/>
<topPen lineWidth="0.0"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="0.0"/>
<rightPen lineWidth="0.0"/>
</box>
<frame>
<reportElement positionType="Float" isPrintRepeatedValues="false" x="0" y="0" width="50" height="20" isRemoveLineWhenBlank="true" isPrintInFirstWholeBand="true" uuid="62f0ab9e-28c4-4a58-935b-f98d26d600e3">
<property name="ShowOutOfBoundContent" value="false"/>
</reportElement>
<subreport>
<reportElement positionType="Float" x="0" y="0" width="50" height="20" uuid="48a7bbe4-b8ce-4a0d-a6e1-6ddd288e5602"/>
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<subreportParameter name="timeList">
<subreportParameterExpression><![CDATA[$F{timeList}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
<subreportExpression><![CDATA[$F{timeTableSubReport}]]></subreportExpression>
</subreport>
</frame>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
Here is the subreport.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<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="timeTableSubReport" pageWidth="559" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="559" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" whenResourceMissingType="Empty" uuid="42c67c01-6232-438f-8149-de04399dfcd2">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="ireport.scriptlethandling" value="0"/>
<property name="ireport.encoding" value="UTF-8"/>
<import value="net.sf.jasperreports.engine.*"/>
<import value="org.apache.commons.collections.CollectionUtils"/>
<import value="java.util.*"/>
<import value="net.sf.jasperreports.engine.data.*"/>
<style name="table 1">
<box>
<pen lineWidth="0.0" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TH" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.0" lineColor="#000000"/>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</style>
<style name="table 1_CH" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.0" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.0" lineColor="#000000"/>
</box>
<conditionalStyle>
<conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
<style backcolor="#FFFFFF"/>
</conditionalStyle>
</style>
<subDataset name="Table LineItems" uuid="183918c2-b66e-4347-ae7b-e891ab0a1d88">
<field name="time" class="java.lang.String"/>
</subDataset>
<parameter name="timeList" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<detail>
<band height="70">
<componentElement>
<reportElement key="table 1" style="table 1" positionType="Float" x="0" y="0" width="504" height="70" uuid="eb4057df-dd6a-40dd-870e-baac8c8afe17">
<property name="local_mesure_unitwidth" value="inch"/>
<property name="com.jaspersoft.studio.unit.width" value="inch"/>
<printWhenExpression><![CDATA[$V{REPORT_COUNT} == 1]]></printWhenExpression>
</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="Table LineItems" uuid="8a44aec8-cdd4-4be3-b47a-620e00bb910a">
<datasetParameter name="REPORT_DATA_SOURCE">
<datasetParameterExpression><![CDATA[$P{timeList}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
<jr:column width="70" uuid="baa7f786-d12a-4234-b9d7-faef6c9f25df">
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<box>
<pen lineWidth="0.0"/>
<topPen lineWidth="0.0"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="0.0"/>
<rightPen lineWidth="0.0"/>
</box>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="70" height="20" uuid="5f84b7ac-c2fe-4426-b91f-6714b470a2bc"/>
<box topPadding="5" leftPadding="2" bottomPadding="5" rightPadding="2">
<topPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="8" isBold="false"/>
<paragraph rightIndent="4"/>
</textElement>
<textFieldExpression><![CDATA[$F{time}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
The output looks like this
P.S. I didn't really pay attention to styling here. Hope this helps someone although I am 7 years late.

iReport 4.1.3 table component never shows the first entry of the dataset

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
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.