Jump to content
We've recently updated our Privacy Statement, available here ×

Grouping the report column as shown in attached image


anand.p
Go to solution Solved by hishamkmr,

Recommended Posts

Hi

I want to group the report columns as shown in the attached image. 

Generally when we add group to the report , it adds group header which pring when group changes but  I want to print like 

----------------------------------------------------------------------------

name1             1                     2                     3                     4

----------------------------------------------------------------------------

name 2            1                     2                     3                     4

----------------------------------------------------------------------------

name 3

-----------------------------------------------------------------------------

      abc             8                         8                     8                     8

-----------------------------------------------------------------------------

     abc2            9                         9                     9                    9

-----------------------------------------------------------------------------

 

here name1, name 2 and name3 are grouped column while abc and abc2 are columns coming under group.  

 

I hve attched one image along with this also which will give you clear picture of what i am looking for exactly.

Please can anyone guid me that how can I group the report in this way.  Need Quick Help

 

Thanks

Anand 

 

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

  • Solution

I am assuming those abc and abc2 are null for other groups.

for eg:

I have a table TEST with columns

GROUP1,SUB,DATA1,DATA2

VALUES in the table

Name1,   null , one, two

NAME2, null, one,two

NAME3,ab,one,two

NAME3,ac,one,two

my query for ireport will be

select group1,sub,data1,data2
from test
group by group1,sub,data1,data2
order by group1
 
Then create group band in ireport with group1
place group1,data1,data2 in group headerband
and give <printWhenExpression> for data1 and data2 as show only when sub is null
 
then place sub,data1,data2 in detail band of the report
and give <printWhenExpression> for sub,data1, and data2 as show only when sub is not null
 
find the below xml code
<?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="test2" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[select group1,sub,data1,data2
from test
group by group1,sub,data1,data2
order by group1]]>
</queryString>
<field name="GROUP1" class="java.lang.String"/>
<field name="SUB" class="java.lang.String"/>
<field name="DATA1" class="java.lang.String"/>
<field name="DATA2" class="java.lang.String"/>
<group name="GROUP1">
<groupExpression><![CDATA[$F{GROUP1}]]></groupExpression>
<groupHeader>
<band height="20">
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{GROUP1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="84" height="20">
<printWhenExpression><![CDATA[new Boolean($F{SUB}==null)]]></printWhenExpression>
</reportElement>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{DATA1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="184" y="0" width="100" height="20">
<printWhenExpression><![CDATA[new Boolean($F{SUB}==null)]]></printWhenExpression>
</reportElement>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{DATA2}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="100" y="0" width="100" height="20">
<printWhenExpression><![CDATA[new Boolean($F{SUB}!=null)]]></printWhenExpression>
</reportElement>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{SUB}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="200" y="0" width="100" height="20">
<printWhenExpression><![CDATA[new Boolean($F{SUB}!=null)]]></printWhenExpression>
</reportElement>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{DATA1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="300" y="0" width="100" height="20">
<printWhenExpression><![CDATA[new Boolean($F{SUB}!=null)]]></printWhenExpression>
</reportElement>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{DATA2}]]></textFieldExpression>
</textField>
</band>
</detail>
<summary>
<band height="29" splitType="Stretch"/>
</summary>
</jasperReport>
-----------------------------------------------------
Run the report you will get the output as given in ur question. also find the jrxml file attached with this. 
 
let me know whether this helped.
 
 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...