I have this data and I want in iReport is group this by number group and color group.
color | number_group | color_group |
red | 1 | primary |
blue | 1 | primary |
yellow| 2 | primary |
orange| 2 | secondary |
violet| 1 | secondary |
green | 1 | secondary |
I want in my report
Color Group: Primary Number: 1
red
blue
Color Group: Primary Number: 2
yellow
Color Group: Secondary Number: 1
violet
green
Color Group: Secondary Number: 2
orange
But in I can only manage to do Add Group > Group Criteria > Group by following expression > choose color_group field.
And the output is this which is not the one that I'm hoping for.
Color Group: Primary Number: 1
red
blue
yellow
Color Group: Secondary Number: 2
orange
violet
green
I think the right solution is using Add Group > Group Criteria > Group by following expression > group expression with text area but I don't know what to put there. Anyone?
Grouping in ReportRight click on the report and click on add group, create group by giving the expression or selecting the fields.
A group can even have more than one header\footer band in the designer, for example to add an header to a group it's sufficent right click on the header element in the outline view (it dosen't matter if it has black color or lightgray because at the moment there aren't other headers) and select the option "Create Band" ...
Group on the concatenation of the two values:
<groupExpression><![CDATA[$F{number_group} + $F{color_group}]]></groupExpression>
Example
<?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="group" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c1d9b4b7-6162-4b17-b871-3cf3b867d1ef">
<queryString>
<![CDATA[]]>
</queryString>
<field name="color" class="java.lang.String"/>
<field name="number_group" class="java.lang.String"/>
<field name="color_group" class="java.lang.String"/>
<group name="myGroup">
<groupExpression><![CDATA[$F{number_group} + $F{color_group}]]></groupExpression>
<groupHeader>
<band height="20">
<textField>
<reportElement mode="Transparent" x="0" y="0" width="300" height="20" forecolor="#3333FF" uuid="b3f3381f-26c1-48d5-953e-ddd017fbf7cf"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA["Color Group: " + $F{color_group} + " Number: " + $F{number_group}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
</group>
<detail>
<band height="15" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="300" height="15" uuid="7337168a-363f-4438-a38e-e4859fb6fdd1"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{color}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
Output
Note: The get exact same order as your expected output the orange record need to be last (order data)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With