Group Expression

I have a datasource passed from a main report to subreport.

This datasource has two columns - one is a date type(say X) and other is a string type(say Y).

Now I want to group data in Y  based on the X. 

I have used a group header with an expression - $F{X}. For some reason I am not getting a proper output.

This is what I want:

2013-1-6

      Value 1

      Value 2

2013-1-5

     Value 3

     Value4

This is what I am getting:

2013-1-6

      Value 1

2013-1-6

      Value 2

2013-1-5

     Value 3

2013-1-5

     Value4

 

What could I be doing wrong? Please help.

jkaur's picture
15
Joined: Jul 24 2012 - 6:04pm
Last seen: 10 years 7 months ago
I am using iReport 4.0.2
jkaur - 10 years 7 months ago

1 Answer:

Is dates really equals? Try to display $F{X}.getTime() in group header and compare displayed values

sanbez's picture
7138
Joined: Jan 11 2011 - 2:06am
Last seen: 2 years 11 months ago

Hi sanbez
Thanks for you reply.
The date is Date type and not a Timestamp. And I cannot do .getTime() on my Field because its a String type.
That means, I have a JRMapCollectionDatasource passed to the subreport, which has both X and Y columns as String (X being converted to String by X.toString()). So the two fields $F{X} and $F{Y} are String type.

I hope that makes sense.
I have attach my subreport which has the groupheader.

jkaur - 10 years 7 months ago

<?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="enrolment_credential_person_skill_sets_subreport" pageWidth="600" pageHeight="802" whenNoDataType="AllSectionsNoDetail" columnWidth="600" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="SKILL_SET" class="java.lang.String"/>
<field name="COMPETENT_DATE" class="java.lang.String"/>
<variable name="COMPETENT_DATE_1" class="java.lang.Integer" resetType="Group" resetGroup="group1" calculation="Count">
<variableExpression><![CDATA[$F{COMPETENT_DATE}]]></variableExpression>
</variable>
<group name="group1">
<groupExpression><![CDATA[$F{COMPETENT_DATE}]]></groupExpression>
</group>
<group name="Competent_Date">
<groupExpression><![CDATA[$F{COMPETENT_DATE}]]></groupExpression>
<groupHeader>
<band height="23">
<textField>
<reportElement x="52" y="0" width="380" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Vijaya" size="16" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{COMPETENT_DATE}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
</group>
<detail>
<band height="18" splitType="Stretch">
<textField>
<reportElement x="218" y="0" width="111" height="18"/>
<textElement verticalAlignment="Middle">
<font fontName="Vijaya" size="16" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{SKILL_SET}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>

jkaur - 10 years 7 months ago

after insert query in this subreport:
select '2013-1-6' competent_date, 'Value 1' skill_set from dual union all
select '2013-1-6' , 'Value 2' from dual union all
select '2013-1-5' , 'Value 3' from dual union all
select '2013-1-5' , 'Value 4' from dual

I am get next output:
2013-1-6
Value 1
Value 2
2013-1-5
Value 3
Value 4

Are you get same result when only subreport run (without main report)?

sanbez - 10 years 7 months ago
show 1 more...

I have finally fixed it!
All I had to do was sort the dataset before it was passed to the datasource.

Thanks.

jkaur - 10 years 7 months ago
Feedback