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.
1 Answer:
Is dates really equals? Try to display $F{X}.getTime() in group header and compare displayed values
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.
<?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>