I have a code in jrxml like.
<detail>
<band height="35">
<componentElement>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="38" y="12" width="457" height=<![CDATA[$P{col1_Header}]]> isRemoveLineWhenBlank="true" />
<hc:html xmlns:hc="http://jasperreports.sourceforge.net/htmlcomponent" xsi:schemaLocation="http://jasperreports.sourceforge.net/htmlcomponent http://jasperreports.sourceforge.net/xsd/htmlcomponent.xsd" scaleType="RetainShape" horizontalAlign="Left" verticalAlign="Middle">
<hc:htmlContentExpression><![CDATA[com.turborep.turbotracker.util.ReportUtils.toHtml($F{InlineNote})]]></hc:htmlContentExpression>
</hc:html>
</componentElement>
<rectangle>
<reportElement isPrintRepeatedValues="false" x="292" y="2" width="65" height="20" forecolor="#FFFFFF" />
</rectangle>
<rectangle>
<reportElement isPrintRepeatedValues="false" x="33" y="2" width="64" height="20" forecolor="#FFFFFF" />
</rectangle>
<rectangle>
<reportElement isPrintRepeatedValues="false" x="357" y="2" width="74" height="20" forecolor="#FFFFFF" />
</rectangle>
<rectangle>
<reportElement isPrintRepeatedValues="false" x="94" y="2" width="71" height="20" forecolor="#FFFFFF" />
</rectangle>
<textField isStretchWithOverflow="true">
<reportElement isPrintRepeatedValues="false" x="43" y="2" width="128" height="20" />
<textFieldExpression><![CDATA[$F{Product}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement isPrintRepeatedValues="false" x="173" y="2" width="100" height="20" isPrintWhenDetailOverflows="true" />
<textFieldExpression><![CDATA[$F{ItemQuantity}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement isPrintRepeatedValues="false" x="273" y="3" width="134" height="20" isPrintWhenDetailOverflows="true" />
<textFieldExpression><![CDATA[$F{Paragraph}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement isPrintRepeatedValues="false" x="407" y="3" width="103" height="20" isPrintInFirstWholeBand="true" />
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[($F{Price} == null) ? "" : "$"+$F{Price}.setScale(2, java.math.RoundingMode.HALF_UP)]]></textFieldExpression>
</textField>
<textField>
<reportElement x="16" y="0" width="23" height="20" />
<textElement>
<font isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<textFieldExpression><![CDATA[$V{REPORT_COUNT}+"."]]></textFieldExpression>
</textField>
</band>
</detail>
where my html content will grow bigger, so i want the html component to have auto height or it should support overflow. Now it is shrinking the size of the components as it grows.
Please help me with this. Thanks in advance.
Related
I have a table on my db that has fields with jsonobject and jsonarray, I need to convert those values into jasperreport
<subDataset name="Dataset" uuid="06d196fb-4ae2-4735-9798-84a7072c4ea6">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="DataAdapter.xml"/>
<parameter name="data" class="java.lang.String"/>
<queryString>
<![CDATA[SELECT data1,data2,data3,data4,data5,data6
FROM ri_table WHERE id = $P{data}]]>
</queryString>
<field name="data1" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="data1"/>
<property name="com.jaspersoft.studio.field.tree.path" value="ri_pj_fugados"/>
</field>
<field name="data2" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="data2"/>
<property name="com.jaspersoft.studio.field.tree.path" value="ri_pj_fugados"/>
</field>
<field name="data3" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="data3"/>
<property name="com.jaspersoft.studio.field.tree.path" value="ri_pj_fugados"/>
</field>
<field name="data4" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="data4"/>
<property name="com.jaspersoft.studio.field.tree.path" value="ri_pj_fugados"/>
</field>
<field name="data5" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="data5"/>
<property name="com.jaspersoft.studio.field.tree.path" value="ri_pj_fugados"/>
</field>
</subDataset>
<parameter name="data" class="java.lang.String"/>
<queryString>
<![CDATA[SELECT data1,data2,data3,data4,data5,data6
FROM ri_table WHERE id = $P{data}]]>
</queryString>
That way I extract the data from the database
<summary>
<band height="50">
<property name="com.jaspersoft.studio.layout"/>
<componentElement>
<reportElement x="0" y="0" width="572" height="50" forecolor="#595959" uuid="1326f896-5433-4071-b733-25f1c836a830">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.table.style.table_header" value="Table 1_TH"/>
<property name="com.jaspersoft.studio.table.style.column_header" value="Table 1_CH"/>
<property name="com.jaspersoft.studio.table.style.detail" value="Table 1_TD"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</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="Dataset" uuid="e3de465d-85b0-414f-9f7e-704f827b366a">
<datasetParameter name="data">
<datasetParameterExpression><![CDATA[$P{data}]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="70" uuid="300d2e97-ff2d-438b-8528-d565f835ccc8">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:columnHeader style="Table 1_CH" height="20" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="70" height="20" forecolor="#FFFFFF" uuid="5c21d9d0-510d-4852-904e-21a49992c04e"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="8" isBold="true"/>
</textElement>
<text><![CDATA[data1]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table 1_TD" height="30">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement mode="Transparent" x="0" y="0" width="70" height="30" forecolor="#595959" backcolor="#FAF5F5" uuid="4b036592-a8fa-405c-ac85-12f7cda5dabd"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="6"/>
</textElement>
<textFieldExpression><![CDATA[$F{data1}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="300d2e97-ff2d-438b-8528-d565f835ccc8">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:columnHeader style="Table 1_CH" height="20" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="90" height="20" forecolor="#FFFFFF" uuid="5c21d9d0-510d-4852-904e-21a49992c04e"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="8" isBold="true"/>
</textElement>
<text><![CDATA[data2]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table 1_TD" height="30">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement mode="Transparent" x="0" y="0" width="90" height="30" forecolor="#595959" backcolor="#FAF5F5" uuid="4b036592-a8fa-405c-ac85-12f7cda5dabd"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="6"/>
</textElement>
<textFieldExpression><![CDATA[$F{data2}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="70" uuid="300d2e97-ff2d-438b-8528-d565f835ccc8">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:columnHeader style="Table 1_CH" height="20" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="70" height="20" forecolor="#FFFFFF" uuid="5c21d9d0-510d-4852-904e-21a49992c04e"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="8" isBold="true"/>
</textElement>
<text><![CDATA[data3]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table 1_TD" height="30">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement mode="Transparent" x="0" y="0" width="70" height="30" forecolor="#595959" backcolor="#FAF5F5" uuid="4b036592-a8fa-405c-ac85-12f7cda5dabd"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="6"/>
</textElement>
<textFieldExpression><![CDATA[$F{data3}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="41" uuid="300d2e97-ff2d-438b-8528-d565f835ccc8">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:columnHeader style="Table 1_CH" height="20" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="41" height="20" forecolor="#FFFFFF" uuid="5c21d9d0-510d-4852-904e-21a49992c04e"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="8" isBold="true"/>
</textElement>
<text><![CDATA[data4]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table 1_TD" height="30">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement mode="Transparent" x="0" y="0" width="41" height="30" forecolor="#595959" backcolor="#FAF5F5" uuid="4b036592-a8fa-405c-ac85-12f7cda5dabd"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="6"/>
</textElement>
<textFieldExpression><![CDATA[$F{data4}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="61" uuid="300d2e97-ff2d-438b-8528-d565f835ccc8">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:columnHeader style="Table 1_CH" height="20" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="61" height="20" forecolor="#FFFFFF" uuid="5c21d9d0-510d-4852-904e-21a49992c04e"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="8" isBold="true"/>
</textElement>
<text><![CDATA[data5]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table 1_TD" height="30">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement mode="Transparent" x="0" y="0" width="61" height="30" forecolor="#595959" backcolor="#FAF5F5" uuid="4b036592-a8fa-405c-ac85-12f7cda5dabd"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="6"/>
</textElement>
<textFieldExpression><![CDATA[$F{data5}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</summary>
That way it creates a table with the generated fields, but in the json data it prints them in the json format
And I need for certain cases to print data2.dato or data2.otherdato
And I don't know how to do it, the same goes for the json array,
I need to iterate the jsons inside the array and print out certain data.
For those fields in your main query, that you know they are in JSON format you could create a JSON/JSONQL datasource that you pass to a subreport/table/list/etc.
The main steps would be:
Create a subDataset for that specific field or class of fields, e.g.:
<subDataset name="JsonFieldDataset" uuid="70d9d3c4-af50-48fc-a8a9-205697b62f0c">
<field name="dato" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="dato"/>
</field>
<field name="otherDato" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="otherDato"/>
</field>
</subDataset>
In the detail band have a component that constructs a JSON/JSONQL datasource. Posting only a simplified output with relevant parts:
<componentElement>
<reportElement />
<jr:table>
<datasetRun subDataset="JsonFieldDataset" uuid="318415a6-a046-4886-b04a-f13c3e9bf6f0">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JsonQLDataSource(new ByteArrayInputStream($F{data2}.getBytes("UTF-8")))]]></dataSourceExpression>
</datasetRun>
<jr:column />
<jr:column />
</jr:table>
</componentElement>
I have a report with a table and a group. I need that the column footer of the report do a sum using the variable retuned of the table. Is it possible?
I did an example. In this example, I want that variable "sumItemValueFromTable" show the value 10000.0. At the moment, the result is 0.0.
This is the JRXML file of the report:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.4.0.final using JasperReports Library version 6.4.1 -->
<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="example_report" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isFloatColumnFooter="true" uuid="98b654fa-866e-4db4-9a3d-372b1e6e06c7">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="datasouce"/>
<style name="Table_TH" 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>
<style name="Table_CH" 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>
<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="items" uuid="940ee07b-57c1-48bd-bbfe-9ee2ac66d304">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="datasouce"/>
<queryString language="json">
<![CDATA[items]]>
</queryString>
<field name="itemName" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="itemName"/>
<fieldDescription><![CDATA[itemName]]></fieldDescription>
</field>
<field name="itemValue" class="java.lang.Double">
<property name="net.sf.jasperreports.json.field.expression" value="itemValue"/>
<fieldDescription><![CDATA[itemValue]]></fieldDescription>
</field>
<variable name="sumItem" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$F{itemValue}]]></variableExpression>
<initialValueExpression><![CDATA[0.0]]></initialValueExpression>
</variable>
</subDataset>
<queryString language="json">
<![CDATA[]]>
</queryString>
<field name="userName" class="java.lang.String">
<fieldDescription><![CDATA[userName]]></fieldDescription>
</field>
<field name="userDescription" class="java.lang.String">
<fieldDescription><![CDATA[userDescription]]></fieldDescription>
</field>
<variable name="sumItemValueGeneral" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$V{sumItemValueFromTable}]]></variableExpression>
<initialValueExpression><![CDATA[0.0]]></initialValueExpression>
</variable>
<variable name="sumItemValueFromTable" class="java.lang.Double" resetType="Group" resetGroup="user">
<initialValueExpression><![CDATA[0.0]]></initialValueExpression>
</variable>
<group name="user">
<groupExpression><![CDATA[$F{userName}]]></groupExpression>
<groupHeader>
<band height="15">
<textField>
<reportElement x="80" y="0" width="720" height="15" uuid="4169f25b-4f54-4aa1-9621-38d9d26fba36"/>
<textElement textAlignment="Left" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{userName} + " - " + $F{userDescription}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="0" width="80" height="15" uuid="6764c7d6-fd26-4057-8120-63f4b55f3100">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="9" isBold="true"/>
</textElement>
<text><![CDATA[User:]]></text>
</staticText>
</band>
</groupHeader>
<groupFooter>
<band height="15">
<staticText>
<reportElement x="0" y="0" width="180" height="15" uuid="b61688ee-94d6-4c74-aa6f-035b7bbd6dbd">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="9" isBold="true"/>
</textElement>
<text><![CDATA[USER SUM]]></text>
</staticText>
<textField>
<reportElement x="180" y="0" width="100" height="14" uuid="919abbde-42c3-4503-bcc8-ad68ffac7950"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{sumItemValueFromTable}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
<title>
<band height="15" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="800" height="15" uuid="b71231cd-1292-4cad-96fb-918dc371bf78">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[My report]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="17" splitType="Stretch">
<staticText>
<reportElement x="0" y="2" width="800" height="15" uuid="5f05f44c-eabb-4aaf-b3c2-6c2512f60f73">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[A page header]]></text>
</staticText>
</band>
</pageHeader>
<columnHeader>
<band height="15" splitType="Stretch">
<staticText>
<reportElement x="80" y="0" width="100" height="15" uuid="f4a14a24-b4cb-46d4-a799-f7401178d6b7">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement x="180" y="0" width="100" height="15" uuid="63b605a9-d94e-449f-b4e8-c5b5fa2352fe">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Value]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="15" splitType="Stretch">
<componentElement>
<reportElement x="80" y="0" width="200" height="15" uuid="36dcd5f4-e9bd-4577-8ff4-dceacfa42263">
<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="com.jaspersoft.studio.unit.height" value="pixel"/>
</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="items" uuid="98564efc-611d-4267-b650-20b8ce408049">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("items")]]></dataSourceExpression>
<returnValue fromVariable="sumItem" toVariable="sumItemValueFromTable"/>
</datasetRun>
<jr:column width="100" uuid="594a2c22-50a2-4cb3-bd1b-5b73edb3e8c5">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<jr:detailCell style="Table_TD" height="15">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<box>
<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>
<textField>
<reportElement x="0" y="0" width="100" height="15" uuid="466d9b29-f34d-4718-8f33-47019eaac2f4">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{itemName}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="100" uuid="5a0cc5e4-46b3-463a-8e5e-b14f2444559f">
<jr:detailCell style="Table_TD" height="15">
<box>
<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>
<textField>
<reportElement x="0" y="0" width="100" height="15" uuid="404014b5-2c4b-4479-8a61-517700f7bdd2"/>
<textElement textAlignment="Right" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{itemValue}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
<columnFooter>
<band height="15" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="180" height="15" uuid="b27a2374-0c07-429c-820f-d44a52faf5b8">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="9" isBold="true"/>
</textElement>
<text><![CDATA[GENERAL SUM]]></text>
</staticText>
<textField evaluationTime="Band">
<reportElement x="180" y="-1" width="100" height="16" uuid="34659bd7-0bb3-4001-9767-91489dc96329"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{sumItemValueGeneral}]]></textFieldExpression>
</textField>
</band>
</columnFooter>
</jasperReport>
And this is the JSON datasource that I used:
[
{
"userName": "User A",
"userDescription": "Description A",
"items": [
{
"itemName": "Item A",
"itemValue": 100.0
},
{
"itemName": "Item B",
"itemValue": 200.0
}
]
},
{
"userName": "User B",
"userDescription": "Description B",
"items": [
{
"itemName": "Item A",
"itemValue": 400.0
},
{
"itemName": "Item B",
"itemValue": 300.0
}
]
}
]
Following your code layout a solution is to define another variable similar to sumItem variabile in your table's subdataset since you can only define 1 return value per variabile in JasperSoft Studio (versione <=6.6.0 has this strange bug), if you are directly editing jrxml you can avoid this step and instead use previous variabile in returnValue.
<variable name="sumItemForTotale" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$F{itemValue}]]></variableExpression>
</variable>
Then return this to variabile sumItemValueGeneral with calculation Sum
<returnValue fromVariable="sumItemForTotale" toVariable="sumItemValueGeneral" calculation="Sum"/>
Now remove your current expression in variabile sumItemValueGeneral and instead set it to Sum
<variable name="sumItemValueGeneral" class="java.lang.Double" calculation="Sum">
<initialValueExpression><![CDATA[0.0]]></initialValueExpression>
</variable>
Yes, you need to set both variabile and returnValue to calculation Sum personally I find it a bit confusing it feels more logical to set only variabile to Sum, but I guess the logic is: if you don't set Sum in returnValue (value will be forced copied as it is directly into variabile) and if you don't set Sum in variabile, variabile will be reinitialized when it get's the new 'add' value.
Full jrxml
<?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="example_report" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isFloatColumnFooter="true" uuid="98b654fa-866e-4db4-9a3d-372b1e6e06c7">
<style name="Table_TH" 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>
<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>
<style name="Table_CH" 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="items" uuid="940ee07b-57c1-48bd-bbfe-9ee2ac66d304">
<queryString language="json">
<![CDATA[items]]>
</queryString>
<field name="itemName" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="itemName"/>
<fieldDescription><![CDATA[itemName]]></fieldDescription>
</field>
<field name="itemValue" class="java.lang.Double">
<property name="net.sf.jasperreports.json.field.expression" value="itemValue"/>
<fieldDescription><![CDATA[itemValue]]></fieldDescription>
</field>
<variable name="sumItem" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$F{itemValue}]]></variableExpression>
<initialValueExpression><![CDATA[0.0]]></initialValueExpression>
</variable>
<variable name="sumItemForTotale" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$F{itemValue}]]></variableExpression>
</variable>
</subDataset>
<queryString language="json">
<![CDATA[]]>
</queryString>
<field name="userName" class="java.lang.String">
<fieldDescription><![CDATA[userName]]></fieldDescription>
</field>
<field name="userDescription" class="java.lang.String">
<fieldDescription><![CDATA[userDescription]]></fieldDescription>
</field>
<variable name="sumItemValueGeneral" class="java.lang.Double" calculation="Sum">
<initialValueExpression><![CDATA[0.0]]></initialValueExpression>
</variable>
<variable name="sumItemValueFromTable" class="java.lang.Double" resetType="Group" resetGroup="user">
<initialValueExpression><![CDATA[0.0]]></initialValueExpression>
</variable>
<group name="user">
<groupExpression><![CDATA[$F{userName}]]></groupExpression>
<groupHeader>
<band height="15">
<textField>
<reportElement x="80" y="0" width="720" height="15" uuid="4169f25b-4f54-4aa1-9621-38d9d26fba36"/>
<textElement textAlignment="Left" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{userName} + " - " + $F{userDescription}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="0" width="80" height="15" uuid="6764c7d6-fd26-4057-8120-63f4b55f3100"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="9" isBold="true"/>
</textElement>
<text><![CDATA[User:]]></text>
</staticText>
</band>
</groupHeader>
<groupFooter>
<band height="15">
<staticText>
<reportElement x="0" y="0" width="180" height="15" uuid="b61688ee-94d6-4c74-aa6f-035b7bbd6dbd"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="9" isBold="true"/>
</textElement>
<text><![CDATA[USER SUM]]></text>
</staticText>
<textField>
<reportElement x="180" y="0" width="100" height="14" uuid="919abbde-42c3-4503-bcc8-ad68ffac7950"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{sumItemValueFromTable}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
<title>
<band height="15" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="800" height="15" uuid="b71231cd-1292-4cad-96fb-918dc371bf78"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[My report]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="17" splitType="Stretch">
<staticText>
<reportElement x="0" y="2" width="800" height="15" uuid="5f05f44c-eabb-4aaf-b3c2-6c2512f60f73"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[A page header]]></text>
</staticText>
</band>
</pageHeader>
<columnHeader>
<band height="15" splitType="Stretch">
<staticText>
<reportElement x="80" y="0" width="100" height="15" uuid="f4a14a24-b4cb-46d4-a799-f7401178d6b7"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement x="180" y="0" width="100" height="15" uuid="63b605a9-d94e-449f-b4e8-c5b5fa2352fe"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Value]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="15" splitType="Stretch">
<componentElement>
<reportElement x="80" y="0" width="200" height="15" uuid="36dcd5f4-e9bd-4577-8ff4-dceacfa42263"/>
<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="items" uuid="98564efc-611d-4267-b650-20b8ce408049">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("items")]]></dataSourceExpression>
<returnValue fromVariable="sumItem" toVariable="sumItemValueFromTable"/>
<returnValue fromVariable="sumItemForTotale" toVariable="sumItemValueGeneral" calculation="Sum"/>
</datasetRun>
<jr:column width="100" uuid="594a2c22-50a2-4cb3-bd1b-5b73edb3e8c5">
<jr:detailCell style="Table_TD" height="15">
<box>
<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>
<textField>
<reportElement x="0" y="0" width="100" height="15" uuid="466d9b29-f34d-4718-8f33-47019eaac2f4"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{itemName}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="100" uuid="5a0cc5e4-46b3-463a-8e5e-b14f2444559f">
<jr:detailCell style="Table_TD" height="15">
<box>
<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>
<textField>
<reportElement x="0" y="0" width="100" height="15" uuid="404014b5-2c4b-4479-8a61-517700f7bdd2"/>
<textElement textAlignment="Right" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{itemValue}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
<columnFooter>
<band height="15" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="180" height="15" uuid="b27a2374-0c07-429c-820f-d44a52faf5b8"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="9" isBold="true"/>
</textElement>
<text><![CDATA[GENERAL SUM]]></text>
</staticText>
<textField evaluationTime="Report">
<reportElement x="180" y="-1" width="100" height="16" uuid="34659bd7-0bb3-4001-9767-91489dc96329"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{sumItemValueGeneral}]]></textFieldExpression>
</textField>
</band>
</columnFooter>
</jasperReport>
Output
I have below json for weekly purchase. Crosstab is used to show weekly purchase of each products. There is target field which is included as rowgroup in the crosstab . When i total targets and weekly the calculation of total target is incorrect.
How can we get total of totals?
sample json.
{
"header": {
"columnName": [
"Product Store1",
"location"
],
"values": [{
"purchase": {
"id":"purchase1001",
"name": "bags",
"location": "MainMarket "
},
"targets":{
"weekly":300
},
"weekSpend": [{
"weekStartDate": 20181105,
"spend": 100
},
{
"weekStartDate": 20181112,
"spend": 200
}
]
},
{
"purchase": {
"id":"purchase1002",
"name": "shoes",
"location": "MainMarket "
},
"targets":{
"weekly":400
},
"weekSpend": [{
"weekStartDate": 20181105,
"spend": 100
},
{
"weekStartDate": 20181112,
"spend": 200
}
]
}
]
}
}
I tried following this link https://community.jaspersoft.com/wiki/incorrect-crosstab-row-group-total-arising-dataset-created-using-right-outer-join
But creating group using product name is giving compilation error.
JRXML that has error total
<?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="XTabReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="33c43d53-f9b3-4cc9-92b2-bedd805d66a9">
<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>
<subDataset name="XTabDS" uuid="9911fa6c-61b7-4952-81bf-4666e3e17fcf">
<field name="weekStartDate" class="java.lang.Integer">
<property name="net.sf.jasperreports.jsonql.field.expression" value="weekStartDate"/>
</field>
<field name="spend" class="java.lang.Integer">
<property name="net.sf.jasperreports.jsonql.field.expression" value="spend"/>
</field>
<field name="name" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^{2}.purchase.name"/>
</field>
<field name="location" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^{2}.purchase.location"/>
</field>
<field name="target" class="java.lang.Integer">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^{2}.targets.weekly"/>
</field>
</subDataset>
<subDataset name="listSubDataset" uuid="01e76955-f29e-4d52-991b-aa0149bfdb37">
<field name="colName" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="[0]"/>
</field>
</subDataset>
<queryString language="jsonql">
<![CDATA[]]>
</queryString>
<title>
<band height="58">
<staticText>
<reportElement x="140" y="10" width="280" height="30" uuid="c8e3d7ad-eeb0-4cd1-8bef-88874e6921d4"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14"/>
</textElement>
<text><![CDATA[List inside Crosstab]]></text>
</staticText>
</band>
</title>
<detail>
<band height="70" splitType="Stretch">
<crosstab>
<reportElement x="0" y="0" width="560" height="70" uuid="79f2afae-ac8b-4442-ac8e-ae1b1f68109f">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.crosstab.style.header" value="Crosstab_CH"/>
<property name="com.jaspersoft.studio.crosstab.style.group" value="Crosstab_CG"/>
<property name="com.jaspersoft.studio.crosstab.style.total" value="Crosstab_CT"/>
<property name="com.jaspersoft.studio.crosstab.style.detail" value="Crosstab_CD"/>
</reportElement>
<crosstabParameter name="listDS" class="net.sf.jasperreports.engine.data.JsonQLDataSource">
<parameterValueExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("header.columnName")]]></parameterValueExpression>
</crosstabParameter>
<crosstabDataset>
<dataset>
<datasetRun subDataset="XTabDS" uuid="73b2e155-5015-451a-8813-7e2ed2f731fb">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("..values..weekSpend.*")]]></dataSourceExpression>
</datasetRun>
</dataset>
</crosstabDataset>
<crosstabHeaderCell>
<cellContents mode="Opaque" style="Crosstab_CD">
<componentElement>
<reportElement x="0" y="0" width="180" height="30" isPrintWhenDetailOverflows="true" uuid="412c6db7-0cfa-4025-80cd-8c450f9eab96">
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
</reportElement>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Horizontal">
<datasetRun subDataset="listSubDataset" uuid="a911c80f-a0b3-4395-bbd7-2c52c67585d3">
<dataSourceExpression><![CDATA[$P{listDS}]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="90">
<textField>
<reportElement x="0" y="0" width="90" height="30" isPrintWhenDetailOverflows="true" uuid="168fd030-81cf-4b80-9766-6f4637c779ec"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
</box>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$F{colName}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</cellContents>
</crosstabHeaderCell>
<rowGroup name="name" width="90" totalPosition="End">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{name}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="e8aa37d7-0921-40a6-8aca-1cccae61d26d"/>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$V{name}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents mode="Opaque" style="Crosstab_CT">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
<textField>
<reportElement x="182" y="0" width="80" height="20" uuid="ff76ebdd-1c14-4924-8bff-392beb7ef1b3"/>
<textFieldExpression><![CDATA[$V{totaltargets}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<rowGroup name="location" width="90" totalPosition="End">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{location}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="86107a55-79be-4170-a2ee-b2a0ae5315e2"/>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$V{location}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents mode="Opaque" style="Crosstab_CG"/>
</crosstabTotalRowHeader>
</rowGroup>
<rowGroup name="target" width="90">
<bucket class="java.lang.Integer">
<bucketExpression><![CDATA[$F{target}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="3c9c5be2-4ced-4db6-8dd2-0f411281cce6"/>
<textFieldExpression><![CDATA[$V{target}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents mode="Opaque" style="Crosstab_CG">
<staticText>
<reportElement x="0" y="0" width="90" height="20" uuid="e14fddff-9658-4dcf-b6a7-78e195e2bba4"/>
<text><![CDATA[Total target]]></text>
</staticText>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="weekStartDate" height="30" totalPosition="End">
<bucket class="java.lang.Integer">
<bucketExpression><![CDATA[$F{weekStartDate}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="90" height="30" uuid="c65fb64a-d89b-4cc3-be28-d76624cb3d93"/>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$V{weekStartDate}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CT"/>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="spend_MEASURE" class="java.lang.Integer">
<measureExpression><![CDATA[$F{spend}]]></measureExpression>
</measure>
<measure name="totalspend_MEASURE" class="java.lang.Integer" calculation="Sum">
<measureExpression><![CDATA[$F{spend}]]></measureExpression>
</measure>
<measure name="totaltargets" class="java.lang.Integer" calculation="Sum">
<measureExpression><![CDATA[$F{target}]]></measureExpression>
</measure>
<crosstabCell width="90" height="20">
<cellContents mode="Opaque" style="Crosstab_CD">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="efb4b6dd-d9d3-4520-a94e-c0010a572b29"/>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$V{spend_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell height="20" columnTotalGroup="weekStartDate">
<cellContents mode="Opaque" style="Crosstab_CT"/>
</crosstabCell>
<crosstabCell width="90" height="0" rowTotalGroup="location">
<cellContents mode="Opaque" style="Crosstab_CG"/>
</crosstabCell>
<crosstabCell height="0" rowTotalGroup="location" columnTotalGroup="weekStartDate">
<cellContents mode="Opaque" style="Crosstab_CT"/>
</crosstabCell>
<crosstabCell width="90" height="20" rowTotalGroup="name">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="9dbc6e03-7cac-4daa-af1a-a8b7b3b6b97c"/>
<textFieldExpression><![CDATA[$V{totalspend_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell height="20" rowTotalGroup="name" columnTotalGroup="weekStartDate">
<cellContents mode="Opaque" style="Crosstab_CT"/>
</crosstabCell>
<crosstabCell width="90" height="20" rowTotalGroup="target">
<cellContents mode="Opaque" style="Crosstab_CG"/>
</crosstabCell>
<crosstabCell height="20" rowTotalGroup="target" columnTotalGroup="weekStartDate">
<cellContents mode="Opaque" style="Crosstab_CT"/>
</crosstabCell>
</crosstab>
</band>
</detail>
</jasperReport>
The output with wrong totals:
I was able to get total for row columns by defining group name in the data set used by crosstab.
Below is the final layout
Below is the modified jrxml notice the data set XTabDS has a group tag for id.
<?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="XTabReport" pageWidth="1000" pageHeight="595" orientation="Landscape" columnWidth="960" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="33c43d53-f9b3-4cc9-92b2-bedd805d66a9">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="release\AOS 19.4\SampleAdapter.xml"/>
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
<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>
<subDataset name="XTabDS" uuid="9911fa6c-61b7-4952-81bf-4666e3e17fcf">
<field name="weekStartDate" class="java.lang.Integer">
<property name="net.sf.jasperreports.jsonql.field.expression" value="weekStartDate"/>
</field>
<field name="spend" class="java.lang.Integer">
<property name="net.sf.jasperreports.jsonql.field.expression" value="spend"/>
</field>
<field name="name" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^{2}.purchase.name"/>
</field>
<field name="location" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^{2}.purchase.location"/>
</field>
<field name="id" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^{2}.purchase.id"/>
</field>
<field name="target" class="java.lang.Integer">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^{2}.targets.weekly"/>
</field>
<group name="namegroup">
<groupExpression><![CDATA[$F{id}]]></groupExpression>
</group>
</subDataset>
<subDataset name="listSubDataset" uuid="01e76955-f29e-4d52-991b-aa0149bfdb37">
<field name="colName" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="[0]"/>
</field>
</subDataset>
<queryString language="jsonql">
<![CDATA[]]>
</queryString>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="58">
<staticText>
<reportElement x="140" y="10" width="280" height="30" uuid="c8e3d7ad-eeb0-4cd1-8bef-88874e6921d4"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14"/>
</textElement>
<text><![CDATA[List inside Crosstab]]></text>
</staticText>
</band>
</title>
<detail>
<band height="315" splitType="Stretch">
<crosstab>
<reportElement x="0" y="30" width="640" height="250" uuid="79f2afae-ac8b-4442-ac8e-ae1b1f68109f">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.crosstab.style.header" value="Crosstab_CH"/>
<property name="com.jaspersoft.studio.crosstab.style.group" value="Crosstab_CG"/>
<property name="com.jaspersoft.studio.crosstab.style.total" value="Crosstab_CT"/>
<property name="com.jaspersoft.studio.crosstab.style.detail" value="Crosstab_CD"/>
</reportElement>
<crosstabParameter name="listDS" class="net.sf.jasperreports.engine.data.JsonQLDataSource">
<parameterValueExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("header.columnName")]]></parameterValueExpression>
</crosstabParameter>
<crosstabDataset>
<dataset>
<datasetRun subDataset="XTabDS" uuid="73b2e155-5015-451a-8813-7e2ed2f731fb">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("..values..weekSpend.*")]]></dataSourceExpression>
</datasetRun>
</dataset>
</crosstabDataset>
<crosstabHeaderCell>
<cellContents mode="Opaque" style="Crosstab_CD">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
<componentElement>
<reportElement x="0" y="0" width="270" height="30" isPrintWhenDetailOverflows="true" uuid="412c6db7-0cfa-4025-80cd-8c450f9eab96">
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
</reportElement>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Horizontal" ignoreWidth="false">
<datasetRun subDataset="listSubDataset" uuid="a911c80f-a0b3-4395-bbd7-2c52c67585d3">
<dataSourceExpression><![CDATA[$P{listDS}]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="270">
<textField>
<reportElement stretchType="ElementGroupBottom" x="0" y="0" width="270" height="30" isPrintWhenDetailOverflows="true" uuid="168fd030-81cf-4b80-9766-6f4637c779ec"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
</box>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$F{colName}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</cellContents>
</crosstabHeaderCell>
<rowGroup name="location" width="90" totalPosition="End">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{location}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
<textField>
<reportElement x="0" y="0" width="90" height="40" uuid="3f1ee208-60d1-412a-9138-7de26110367c"/>
<textFieldExpression><![CDATA[$V{location}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents mode="Opaque" style="Crosstab_CG">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
<textField>
<reportElement x="180" y="0" width="90" height="20" uuid="1e206bac-b8b9-4e65-8d12-57881505a4b2"/>
<textFieldExpression><![CDATA[$V{TOTAL}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<rowGroup name="name" width="90">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{name}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="90" height="40" uuid="e8aa37d7-0921-40a6-8aca-1cccae61d26d"/>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$V{name}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents mode="Opaque" style="Crosstab_CT">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
<textField>
<reportElement x="182" y="0" width="80" height="20" uuid="ff76ebdd-1c14-4924-8bff-392beb7ef1b3"/>
<textFieldExpression><![CDATA[$V{TOTAL}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<rowGroup name="target" width="90">
<bucket class="java.lang.Integer">
<bucketExpression><![CDATA[$F{target}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="90" height="40" uuid="3c9c5be2-4ced-4db6-8dd2-0f411281cce6"/>
<textFieldExpression><![CDATA[$V{target}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents mode="Opaque" style="Crosstab_CG">
<staticText>
<reportElement x="0" y="0" width="0" height="0" uuid="e14fddff-9658-4dcf-b6a7-78e195e2bba4"/>
<text><![CDATA[Total target]]></text>
</staticText>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="weekStartDate" height="30" totalPosition="End">
<bucket class="java.lang.Integer">
<bucketExpression><![CDATA[$F{weekStartDate}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="90" height="30" uuid="c65fb64a-d89b-4cc3-be28-d76624cb3d93"/>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$V{weekStartDate}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CT"/>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="spend_MEASURE" class="java.lang.Integer">
<measureExpression><![CDATA[$F{spend}]]></measureExpression>
</measure>
<measure name="totalspend_MEASURE" class="java.lang.Integer" calculation="Sum">
<measureExpression><![CDATA[$F{spend}]]></measureExpression>
</measure>
<measure name="totaltargets" class="java.lang.Integer" calculation="Sum">
<measureExpression><![CDATA[$F{target}]]></measureExpression>
</measure>
<measure name="TOTAL" class="java.lang.Integer" calculation="Sum">
<measureExpression><![CDATA[$V{namegroup_COUNT} == 1 ? $F{target} : 0]]></measureExpression>
</measure>
<crosstabCell width="90" height="40">
<cellContents mode="Opaque" style="Crosstab_CD">
<textField>
<reportElement x="0" y="0" width="90" height="40" uuid="efb4b6dd-d9d3-4520-a94e-c0010a572b29"/>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$V{spend_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell height="40" columnTotalGroup="weekStartDate">
<cellContents mode="Opaque" style="Crosstab_CT"/>
</crosstabCell>
<crosstabCell width="90" height="20" rowTotalGroup="name">
<cellContents mode="Opaque" style="Crosstab_CT"/>
</crosstabCell>
<crosstabCell height="20" rowTotalGroup="name" columnTotalGroup="weekStartDate">
<cellContents mode="Opaque" style="Crosstab_CT"/>
</crosstabCell>
<crosstabCell width="90" height="20" rowTotalGroup="target">
<cellContents mode="Opaque" style="Crosstab_CG"/>
</crosstabCell>
<crosstabCell height="20" rowTotalGroup="target" columnTotalGroup="weekStartDate">
<cellContents mode="Opaque" style="Crosstab_CT"/>
</crosstabCell>
<crosstabCell width="90" height="20" rowTotalGroup="location">
<cellContents mode="Opaque" style="Crosstab_CG">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="8c4215e9-f710-45ea-84a1-3a5c0adc6619"/>
<textFieldExpression><![CDATA[$V{totalspend_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell height="20" rowTotalGroup="location" columnTotalGroup="weekStartDate">
<cellContents mode="Opaque" style="Crosstab_CT"/>
</crosstabCell>
</crosstab>
</band>
</detail>
</jasperReport>
i had need to show crosstabHeaderCell columns dynamically from string array.
this is a json
{
"header": {
"columnName": [
"Product Store1",
"location"
],
"values": [{
"purchase": {
"name": "bags",
"location": "MainMarket "
},
"weekSpend": [{
"weekStartDate": 20181105,
"spend": 100
},
{
"weekStartDate": 20181112,
"spend": 200
}
]
},
{
"purchase": {
"name": "shoes",
"location": "MainMarket "
},
"weekSpend": [{
"weekStartDate": 20181105,
"spend": 100
},
{
"weekStartDate": 20181112,
"spend": 200
}
]
}
]
}
I want to show crosstabHeaderCell from list of values of array columnName in cross tab.
from the above json I am able to iterate and show product name and location as rows and weekSpend as column with data set of crosstab as
<crosstabDataset isDataPreSorted="true">
<dataset>
<datasetRun subDataset="crossTabDataSet" uuid="e7b27508-8a48-4785-a48e-c646249df9a9">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("..values(#size > 0)..weekSpend.*")]]></dataSourceExpression>
</datasetRun>
</dataset>
</crosstabDataset>
when i specify list component for crosstabHeaderCell as below i am getting error parameter REPORT_DATA_SOURCE not found.
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Horizontal" ignoreWidth="true">
<datasetRun subDataset="listcol" uuid="a13d0691-5b9e-4d9f-aaa0-9d0ff0b67b78">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("$.columnName.*")]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="100">
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="99c3d5fe-9f90-4efc-bdab-4371eee17d54"/>
<textFieldExpression><![CDATA[$F{namecol}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
the dataset listcol is defined as
<subDataset name="listcol" uuid="2630f2ff-b912-4f05-8189-7a5d47eada9e">
<field name="namecol" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="[0]"/>
</field>
</subDataset>
how can a i refer to list of values from crosstab data set. why does list fail with parameter not found exception for REPORT_DATA_SOURCE.
can we set the REPORT_DATA_SOURCE value from crosstab dataset to be used by inner dataset.
if i remove REPORT_DATA_SOURCE jr:list and use querystring listcol as $.columnName.*. i get blank in crosstabHeaderCell
Expected output is
Thanks
Anjana,
You need to make use of crosstabParameters in order to pass data from the enclosing report, like so:
<?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="XTabReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="33c43d53-f9b3-4cc9-92b2-bedd805d66a9">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="json_crosstab/DataAdapter.xml"/>
<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>
<subDataset name="XTabDS" uuid="9911fa6c-61b7-4952-81bf-4666e3e17fcf">
<field name="weekStartDate" class="java.lang.Integer">
<property name="net.sf.jasperreports.jsonql.field.expression" value="weekStartDate"/>
</field>
<field name="spend" class="java.lang.Integer">
<property name="net.sf.jasperreports.jsonql.field.expression" value="spend"/>
</field>
<field name="name" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^{2}.purchase.name"/>
</field>
<field name="location" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^{2}.purchase.location"/>
</field>
</subDataset>
<subDataset name="listSubDataset" uuid="01e76955-f29e-4d52-991b-aa0149bfdb37">
<field name="colName" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="[0]"/>
</field>
</subDataset>
<queryString language="jsonql">
<![CDATA[]]>
</queryString>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="58">
<staticText>
<reportElement x="140" y="10" width="280" height="30" uuid="c8e3d7ad-eeb0-4cd1-8bef-88874e6921d4"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14"/>
</textElement>
<text><![CDATA[List inside Crosstab]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="30" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="70" splitType="Stretch">
<crosstab>
<reportElement x="0" y="0" width="560" height="70" uuid="79f2afae-ac8b-4442-ac8e-ae1b1f68109f">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.crosstab.style.header" value="Crosstab_CH"/>
<property name="com.jaspersoft.studio.crosstab.style.group" value="Crosstab_CG"/>
<property name="com.jaspersoft.studio.crosstab.style.total" value="Crosstab_CT"/>
<property name="com.jaspersoft.studio.crosstab.style.detail" value="Crosstab_CD"/>
</reportElement>
<crosstabParameter name="listDS" class="net.sf.jasperreports.engine.data.JsonQLDataSource">
<parameterValueExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("header.columnName")]]></parameterValueExpression>
</crosstabParameter>
<crosstabDataset>
<dataset>
<datasetRun subDataset="XTabDS" uuid="73b2e155-5015-451a-8813-7e2ed2f731fb">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("..values..weekSpend.*")]]></dataSourceExpression>
</datasetRun>
</dataset>
</crosstabDataset>
<crosstabHeaderCell>
<cellContents>
<componentElement>
<reportElement x="0" y="0" width="180" height="30" isPrintWhenDetailOverflows="true" uuid="412c6db7-0cfa-4025-80cd-8c450f9eab96">
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
</reportElement>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Horizontal">
<datasetRun subDataset="listSubDataset" uuid="a911c80f-a0b3-4395-bbd7-2c52c67585d3">
<dataSourceExpression><![CDATA[$P{listDS}]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="90">
<textField>
<reportElement x="0" y="0" width="90" height="30" isPrintWhenDetailOverflows="true" uuid="168fd030-81cf-4b80-9766-6f4637c779ec"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
</box>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$F{colName}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</cellContents>
</crosstabHeaderCell>
<rowGroup name="name" width="90" totalPosition="End">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{name}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="e8aa37d7-0921-40a6-8aca-1cccae61d26d"/>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$V{name}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents/>
</crosstabTotalRowHeader>
</rowGroup>
<rowGroup name="location" width="90" totalPosition="End">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{location}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="86107a55-79be-4170-a2ee-b2a0ae5315e2"/>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$V{location}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents/>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="weekStartDate" height="30" totalPosition="End">
<bucket class="java.lang.Integer">
<bucketExpression><![CDATA[$F{weekStartDate}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="90" height="30" uuid="c65fb64a-d89b-4cc3-be28-d76624cb3d93"/>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$V{weekStartDate}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents/>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="spend_MEASURE" class="java.lang.Integer">
<measureExpression><![CDATA[$F{spend}]]></measureExpression>
</measure>
<crosstabCell width="90" height="20">
<cellContents mode="Opaque" style="Crosstab_CD">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="efb4b6dd-d9d3-4520-a94e-c0010a572b29"/>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$V{spend_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell height="20" columnTotalGroup="weekStartDate">
<cellContents/>
</crosstabCell>
<crosstabCell width="90" height="0" rowTotalGroup="location">
<cellContents/>
</crosstabCell>
<crosstabCell height="0" rowTotalGroup="location" columnTotalGroup="weekStartDate">
<cellContents/>
</crosstabCell>
<crosstabCell width="90" height="20" rowTotalGroup="name">
<cellContents/>
</crosstabCell>
<crosstabCell height="20" rowTotalGroup="name" columnTotalGroup="weekStartDate">
<cellContents/>
</crosstabCell>
</crosstab>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
with the following output:
I met a rather difficult problem to describe but the solution will be simple I think. Let's go!
I have a database with 4 tables:
Imputation:
Hours INT(11)
ToBeBilled TINYINT(1)
Day DATE
Description VARCHAR(256)
Employee:
Name VARCHAR(50)
Firstname VARCHAR(50)
Project:
Name VARCHAR(50)
TimeSheet:
Id INT(11)
I use these 4 tables to create the following crosstab in my report: http://framacalc.org/q3y7281ono
I use some parameters:
Global_Liste_Projets
Select
Project.Name As Projet
From
Project
Order By
Projet
Global_Liste_Noms
Select
Employee.Name As NOM,
Employee.Firstname As Prenom
From
Employee
Order By
NOM,
Prenom
Here is my SQL query :
SELECT
Imputation.`Hours` AS Heures,
Imputation.`ToBeBilled` AS Facturable,
Imputation.`Day` AS Jours,
Employee.`Name` AS NOM,
Project.`Name` AS Projet,
TimeSheet.`Id` AS TimeSheet_Id,
Imputation.`Description` AS Commentaire,
Employee.`Firstname` AS Prenom
FROM
`Project` Project INNER JOIN `Imputation` Imputation ON Project.`Id` = Imputation.`Project_Id`
INNER JOIN `TimeSheet` TimeSheet ON Imputation.`TimeSheet_Id` = TimeSheet.`Id`
INNER JOIN `Employee` Employee ON TimeSheet.`Employee_Id` = Employee.`Id`
WHERE
Imputation.Day BETWEEN $P{Global_Date_From}AND$P{Global_Date_To}
AND $X{ IN ,Project.`Name`,Global_Liste_Projets}
AND $X{ IN ,Employee.`Name`,Global_Liste_Noms}
ORDER BY
Jours ASC,
Projet ASC,
NOM ASC
So, report generation is going well. But when I read my final report and there is more than one imputation filled in billable or non-billable for a specific date, there is only one imputation which appears! Instead there have several. When I do not crosstab, I see all imputations. So I think my problem is located in my crosstab?
My problem : oi61.tinypic.com/96jh3l.jpg and what I want : oi62.tinypic.com/10d7ebk.jpg. And a document in addition to try to explain slightly better my problem: framacalc.org/q3y7281ono.
Has anyone ever had a similar problem?
If I was not clear or missing information, do not hesitate :)
My complete XML :
<?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="MyApp - TabCroise Projets" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5dcc996d-323f-4f19-834a-0b0c1ff4fbab">
<property name="ireport.jasperserver.reportUnit" value="/dev/MyApp_-_TabCroise_Projets_1"/>
<property name="ireport.jasperserver.url" value="http://jasperprod.mycompany.com:8080/jasperserver/services/repository"/>
<style name="Crosstab Data Text" hAlign="Center"/>
<style name="mycompanyStyleConditionnel">
<conditionalStyle>
<conditionExpression><![CDATA[$V{ProjetMeasure}.equals( "mycompany - Défaut" )]]></conditionExpression>
<style forecolor="#FF0000" backcolor="#FFAFAF" isBlankWhenNull="false">
<pen lineColor="#000000"/>
</style>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[$V{ProjetMeasure}.equals( "mycompany - Previsionnel" )]]></conditionExpression>
<style forecolor="#FF0000" backcolor="#FFAFAF" isBlankWhenNull="false">
<pen lineColor="#000000"/>
</style>
</conditionalStyle>
</style>
<parameter name="Global_Date_From" class="java.util.Date">
<defaultValueExpression><![CDATA["01-01-2014"]]></defaultValueExpression>
</parameter>
<parameter name="Global_Date_To" class="java.util.Date">
<defaultValueExpression><![CDATA["12-31-2014"]]></defaultValueExpression>
</parameter>
<parameter name="Global_Liste_Noms" class="java.util.Collection">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="Global_Liste_Projets" class="java.util.Collection">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT
Imputation.`Hours` AS Heures,
Imputation.`ToBeBilled` AS Facturable,
Imputation.`Day` AS Jours,
Employee.`Name` AS NOM,
Project.`Name` AS Projet,
TimeSheet.`Id` AS TimeSheet_Id,
Imputation.`Description` AS Commentaire,
Employee.`Firstname` AS Prenom
FROM
`Project` Project INNER JOIN `Imputation` Imputation ON Project.`Id` = Imputation.`Project_Id`
INNER JOIN `TimeSheet` TimeSheet ON Imputation.`TimeSheet_Id` = TimeSheet.`Id`
INNER JOIN `Employee` Employee ON TimeSheet.`Employee_Id` = Employee.`Id`
WHERE
Imputation.Day BETWEEN $P{Global_Date_From}AND$P{Global_Date_To}
AND $X{ IN ,Project.`Name`,Global_Liste_Projets}
AND $X{ IN ,Employee.`Name`,Global_Liste_Noms}
ORDER BY
Jours ASC,
Projet ASC,
NOM ASC]]>
</queryString>
<field name="Heures" class="java.lang.Integer"/>
<field name="Facturable" class="java.lang.Boolean"/>
<field name="Jours" class="java.sql.Date"/>
<field name="NOM" class="java.lang.String"/>
<field name="Projet" class="java.lang.String"/>
<field name="TimeSheet_Id" class="java.lang.Integer"/>
<field name="Commentaire" class="java.lang.String"/>
<field name="Prenom" class="java.lang.String"/>
<summary>
<band height="42" splitType="Stretch">
<crosstab>
<reportElement uuid="ae07f183-bdcd-4d36-a7bb-d1b9bd70d324" x="0" y="0" width="802" height="42"/>
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2"/>
<rowGroup name="NOM" width="119">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{NOM}+", "+$F{Prenom}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents backcolor="#F0F8FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField isStretchWithOverflow="true">
<reportElement uuid="123177dd-6b7b-44e6-a57f-1068dbef6078" style="Crosstab Data Text" x="0" y="0" width="119" height="50"/>
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{NOM}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents/>
</crosstabTotalRowHeader>
</rowGroup>
<rowGroup name="Facturable" width="96">
<bucket class="java.lang.Boolean">
<bucketExpression><![CDATA[$F{Facturable}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents backcolor="#F0F8FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField isStretchWithOverflow="true">
<reportElement uuid="ed64aa06-4e25-490e-b01f-abc509c87275" style="Crosstab Data Text" x="0" y="0" width="96" height="25"/>
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA["Facturable : "+$V{Facturable}]]></textFieldExpression>
</textField>
<staticText>
<reportElement uuid="851b0620-71bd-4bf5-9b59-7b8010b0d931" style="Crosstab Data Text" x="0" y="25" width="96" height="25"/>
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Middle"/>
<text><![CDATA[Commentaire]]></text>
</staticText>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents/>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="Jours" height="30">
<bucket class="java.sql.Date">
<bucketExpression><![CDATA[$F{Jours}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents backcolor="#F0F8FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField isStretchWithOverflow="true" pattern="dd/MM/yyyy">
<reportElement uuid="3d7232fc-1dc1-4992-a0c9-987807cf5396" style="Crosstab Data Text" x="0" y="0" width="170" height="30"/>
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{Jours}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents/>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="ProjetMeasure" class="java.lang.String">
<measureExpression><![CDATA[$F{Projet}]]></measureExpression>
</measure>
<measure name="ProjetCommentaire" class="java.lang.String">
<measureExpression><![CDATA[$F{Commentaire}]]></measureExpression>
</measure>
<crosstabCell width="170" height="50">
<cellContents>
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true">
<reportElement uuid="3e8d13d3-082e-49ff-9ef1-899959d21856" style="mycompanyStyleConditionnel" mode="Opaque" x="0" y="0" width="170" height="25" forecolor="#000000"/>
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{ProjetMeasure}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="c8b997a0-ed98-489f-969f-5430ef550bcd" style="Crosstab Data Text" x="0" y="25" width="170" height="25"/>
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="0.0"/>
<rightPen lineWidth="0.0"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{ProjetCommentaire}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell height="25" rowTotalGroup="NOM">
<cellContents backcolor="#005FB3" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement uuid="596e5a5a-7a8f-40fe-80e1-fc6a94c6ddbd" style="Crosstab Data Text" x="0" y="0" width="50" height="25" forecolor="#FFFFFF"/>
<textElement/>
<textFieldExpression><![CDATA[$V{ProjetMeasure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="50" columnTotalGroup="Jours">
<cellContents backcolor="#BFE1FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement uuid="64b759b2-b2cb-4769-8771-3b95451a4385" style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
<textElement/>
<textFieldExpression><![CDATA[$V{ProjetMeasure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell rowTotalGroup="NOM" columnTotalGroup="Jours">
<cellContents backcolor="#005FB3" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement uuid="7eb03da8-5b6c-4f9f-a0db-22894bc6f523" style="Crosstab Data Text" x="0" y="0" width="50" height="25" forecolor="#FFFFFF"/>
<textElement/>
<textFieldExpression><![CDATA[$V{ProjetMeasure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell height="25" rowTotalGroup="Facturable">
<cellContents backcolor="#BFE1FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement uuid="5f21a061-8bf6-4026-9f23-2c12653f0459" style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
<textElement/>
<textFieldExpression><![CDATA[$V{ProjetMeasure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell rowTotalGroup="Facturable" columnTotalGroup="Jours">
<cellContents backcolor="#BFE1FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement uuid="a674fb2c-22f9-4c0c-87cc-0570b3430f68" style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
<textElement/>
<textFieldExpression><![CDATA[$V{ProjetMeasure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</summary>
</jasperReport>