jasper-reportssubreport

Jasper Report Gouping doesnt work for subreport data


I have a MAIN report and then a subreport that it is given the data from the MAIN report like this:

        <subreport>
            <reportElement x="0" y="0" width="555" height="224" uuid="b72a4572-ac0d-4a54-b57e-86e0420d1d94"/>
            <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{sortedPositions})]]></dataSourceExpression>
            <subreportExpression><![CDATA["/storage/intranet/balancing/templates/INVOICE_POSITIONS_PICASSO_TEMPLATE.jasper"]]></subreportExpression>
        </subreport>

sortedPositions has the following fields

When i try to group by any of the sortedPositions fileds the grouping doesn't work. When i tried to book from the productConfiguration.field the grouping works!

The problem i that the field on which i want to group by is not in the productConfiguration and getting it directly from the sortedPositions doesn;t group as expected.

Here is the xml:

<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="INVOICE_POSITIONS_PICASSO_TEMPLATE" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="2e9314a9-2d41-428a-91e9-63a890b65110">
<property name="ireport.zoom" value="1.6105100000000019"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<field name="quantity" class="java.math.BigDecimal"/>
<field name="id" class="java.lang.Long"/>
<field name="value" class="java.math.BigDecimal"/>
<field name="corridor" class="java.lang.String">
    <fieldDescription><![CDATA[productConfiguration.invoicePositionList.get(0).corridor]]></fieldDescription>
</field>
<field name="description" class="java.lang.String"/>
<field name="productName" class="java.lang.String">
    <fieldDescription><![CDATA[productConfiguration.product.name]]></fieldDescription>
</field>
<field name="invoiceConfigurationId" class="java.lang.Long">
    <fieldDescription><![CDATA[productConfiguration.invoiceConfiguration.id]]></fieldDescription>
</field>
<field name="productDescription" class="java.lang.String">
    <fieldDescription><![CDATA[productConfiguration.description]]></fieldDescription>
</field>
<field name="productConfigId" class="java.lang.Long">
    <fieldDescription><![CDATA[productConfiguration.id]]></fieldDescription>
</field>
<field name="period" class="java.sql.Timestamp">
    <fieldDescription><![CDATA[invoice.period]]></fieldDescription>
</field>
<variable name="sumValueFinal" class="java.math.BigDecimal" resetType="Group" resetGroup="ProductGroup" calculation="Sum">
    <variableExpression><![CDATA[$F{value}.abs()]]></variableExpression>
</variable>
<group name="ProductGroup">
    <groupExpression><![CDATA[$F{corridor}]]></groupExpression>
    <groupFooter>
        <band height="58">
            <staticText>
                <reportElement mode="Opaque" x="0" y="37" width="455" height="20" backcolor="#CCCCCC" uuid="87ce8c73-7c58-4775-87e4-307521c9f0fe"/>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font fontName="SansSerif" size="9" isBold="true"/>
                    <paragraph rightIndent="2"/>
                </textElement>
                <text><![CDATA[Subtotal:]]></text>
            </staticText>
            <textField pattern="#,##0.00" isBlankWhenNull="true">
                <reportElement mode="Opaque" x="460" y="37" width="95" height="20" backcolor="#CCCCCC" uuid="5456221b-3dee-46fc-a9a4-999da7067898"/>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font fontName="SansSerif" size="9"/>
                    <paragraph rightIndent="2"/>
                </textElement>
                <textFieldExpression><![CDATA[$V{sumValueFinal}.abs()]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement mode="Opaque" x="0" y="8" width="45" height="20" backcolor="#FFFFFF" uuid="e3207aed-06dc-4e00-9eac-adab729b841b"/>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font fontName="SansSerif" size="9" isBold="true"/>
                    <paragraph rightIndent="2"/>
                </textElement>
                <text><![CDATA[GROUP FINAL]]></text>
            </staticText>
            <textField pattern="#,##0.00" isBlankWhenNull="true">
                <reportElement mode="Opaque" x="45" y="8" width="102" height="20" backcolor="#99FF99" uuid="e26a9f2a-b3c1-44df-b088-29f42dfea069"/>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font fontName="SansSerif" size="9"/>
                    <paragraph rightIndent="2"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{productName}]]></textFieldExpression>
            </textField>
            <textField pattern="#,##0.00" isBlankWhenNull="true">
                <reportElement mode="Opaque" x="455" y="8" width="95" height="20" backcolor="#99FF99" uuid="e1f7c353-c700-4d8a-9aa8-1c17c2c94743"/>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font fontName="SansSerif" size="9"/>
                    <paragraph rightIndent="2"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{value}.abs()]]></textFieldExpression>
            </textField>
            <textField pattern="#,##0.00" isBlankWhenNull="true">
                <reportElement mode="Opaque" x="265" y="8" width="95" height="20" backcolor="#99FF99" uuid="7c9b2c7f-22c9-492f-a103-8047690a0080"/>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font fontName="SansSerif" size="9"/>
                    <paragraph rightIndent="2"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{corridor}]]></textFieldExpression>
            </textField>
            <textField pattern="#,##0.00" isBlankWhenNull="true">
                <reportElement mode="Opaque" x="360" y="8" width="95" height="20" backcolor="#99FF99" uuid="351f7355-61aa-4c38-a2e7-1250f965f2eb"/>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font fontName="SansSerif" size="9"/>
                    <paragraph rightIndent="2"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{quantity}.abs()]]></textFieldExpression>
            </textField>
            <textField pattern="#,##0.00" isBlankWhenNull="true">
                <reportElement mode="Opaque" x="147" y="8" width="102" height="20" backcolor="#99FF99" uuid="3a2a9adb-2873-43e2-b8f5-48e3df353572"/>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font fontName="SansSerif" size="9"/>
                    <paragraph rightIndent="2"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{quantity}]]></textFieldExpression>
            </textField>
        </band>
    </groupFooter>
</group>

For reference the description -> NOT group correctly on the other hand the productDescription -> group correctly!


Solution

  • The issue was that the sortedPosition that i was "feeding" to the subreport wasn't properly and correctly sorted! Be careful the jasper group only makes one iteration through the data and the dataSource that you use for grouping should be sorted according what you want to group.