anand.p Posted October 3, 2013 Share Posted October 3, 2013 HiI 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 ThanksAnand Link to comment Share on other sites More sharing options...
hishamkmr Posted October 3, 2013 Share Posted October 3, 2013 can please tell what the value will be for abc and abc2 for group name1 and name2?? is it null?? Link to comment Share on other sites More sharing options...
Solution hishamkmr Posted October 3, 2013 Solution Share Posted October 3, 2013 I am assuming those abc and abc2 are null for other groups.for eg:I have a table TEST with columnsGROUP1,SUB,DATA1,DATA2VALUES in the tableName1, null , one, twoNAME2, null, one,twoNAME3,ab,one,twoNAME3,ac,one,twomy query for ireport will beselect group1,sub,data1,data2from testgroup by group1,sub,data1,data2order by group1 Then create group band in ireport with group1place group1,data1,data2 in group headerbandand give <printWhenExpression> for data1 and data2 as show only when sub is null then place sub,data1,data2 in detail band of the reportand 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,data2from testgroup by group1,sub,data1,data2order 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 More sharing options...
gocmenally Posted October 3, 2013 Share Posted October 3, 2013 use crosstab. it will group for u. Link to comment Share on other sites More sharing options...
anand.p Posted October 4, 2013 Author Share Posted October 4, 2013 Thank You hishamkmr I did it not as exactly as you said but yes your suggestion helped me a lot thank you very much for your quick help :) Regards Anand Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now