jasper reports - Group several same value field into a single cell -
first of all, records shown in table table component not in report one.
the results looks this:
years months summonth sumquarter ----- ------ -------- ---------- 2009 jan 130984 432041 feb 146503 mar 154554 apr 147917 435150 may 131822 jun 155411 jul 144000 424806 aug 130369 sep 150437 oct 112137 400114 nov 152057 dec 135920 ===================================== jan-dec 1692111 ===================================== 2010 jan 139927 417564 feb 154940 mar 122697 apr 163257 413305 may 124999 jun 125049 jul 145127 427612 aug 138804 sep 143681 oct 143398 406381 nov 125351 dec 137632 ===================================== jan-dec 1664862 =====================================
the sumquarter column shows sum of each quarter in year.
they not printed when repeated value of field.
the question how group column of sumquarter, first printed repeated value in each row join next repeated value become single cell until meets non-repeated value?
you can see in image. below image table shows , solution preferred group 3 months of sum single cell.
here image:
you can use sample:
<?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="year_sum_quarter" 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[]]> </querystring> <field name="year" class="java.lang.integer"/> <field name="month" class="java.lang.string"/> <field name="sum" class="java.lang.integer"/> <field name="q" class="java.lang.integer"/> <variable name="yearsum" class="java.lang.integer" resettype="group" resetgroup="yeargroup" calculation="sum"> <variableexpression><![cdata[$f{sum}]]></variableexpression> </variable> <variable name="qsum" class="java.lang.integer" resettype="group" resetgroup="quatergroup" calculation="sum"> <variableexpression><![cdata[$f{sum}]]></variableexpression> </variable> <group name="yeargroup"> <groupexpression><![cdata[$f{year}]]></groupexpression> <groupfooter> <band height="20"> <textfield> <reportelement x="100" y="0" width="100" height="20"/> <box leftpadding="10"> <toppen linewidth="1.0"/> <leftpen linewidth="0.0"/> <bottompen linewidth="1.0"/> <rightpen linewidth="0.0"/> </box> <textelement/> <textfieldexpression><![cdata["jan-dec, " + $f{year}]]></textfieldexpression> </textfield> <textfield> <reportelement x="200" y="0" width="100" height="20"/> <box leftpadding="0"> <toppen linewidth="1.0"/> <leftpen linewidth="0.0"/> <bottompen linewidth="1.0"/> <rightpen linewidth="0.0"/> </box> <textelement/> <textfieldexpression><![cdata[$v{yearsum}]]></textfieldexpression> </textfield> <statictext> <reportelement x="0" y="0" width="100" height="20"/> <box> <toppen linewidth="1.0"/> <leftpen linewidth="1.0"/> <bottompen linewidth="1.0"/> <rightpen linewidth="0.0"/> </box> <textelement textalignment="center" verticalalignment="middle"> <font isbold="true" isitalic="true"/> </textelement> <text><![cdata[]]></text> </statictext> <statictext> <reportelement x="300" y="0" width="100" height="20"/> <box> <toppen linewidth="1.0"/> <leftpen linewidth="0.0"/> <bottompen linewidth="1.0"/> <rightpen linewidth="1.0"/> </box> <textelement textalignment="center" verticalalignment="middle"> <font isbold="true" isitalic="true"/> </textelement> <text><![cdata[]]></text> </statictext> </band> </groupfooter> </group> <group name="quatergroup"> <groupexpression><![cdata[$f{year} + $f{q}]]></groupexpression> </group> <columnheader> <band height="50"> <statictext> <reportelement x="100" y="30" width="100" height="20"/> <box> <toppen linewidth="1.0"/> <leftpen linewidth="1.0"/> <bottompen linewidth="1.0"/> <rightpen linewidth="1.0"/> </box> <textelement textalignment="center" verticalalignment="middle"> <font isbold="true" isitalic="true"/> </textelement> <text><![cdata[month]]></text> </statictext> <statictext> <reportelement x="0" y="30" width="100" height="20"/> <box> <toppen linewidth="1.0"/> <leftpen linewidth="1.0"/> <bottompen linewidth="1.0"/> <rightpen linewidth="1.0"/> </box> <textelement textalignment="center" verticalalignment="middle"> <font isbold="true" isitalic="true"/> </textelement> <text><![cdata[year]]></text> </statictext> <statictext> <reportelement x="200" y="30" width="100" height="20"/> <box> <toppen linewidth="1.0"/> <leftpen linewidth="1.0"/> <bottompen linewidth="1.0"/> <rightpen linewidth="1.0"/> </box> <textelement textalignment="center" verticalalignment="middle"> <font isbold="true" isitalic="true"/> </textelement> <text><![cdata[month sum]]></text> </statictext> <statictext> <reportelement x="300" y="30" width="100" height="20"/> <box> <toppen linewidth="1.0"/> <leftpen linewidth="1.0"/> <bottompen linewidth="1.0"/> <rightpen linewidth="1.0"/> </box> <textelement textalignment="center" verticalalignment="middle"> <font isbold="true" isitalic="true"/> </textelement> <text><![cdata[quarter sum]]></text> </statictext> </band> </columnheader> <detail> <band height="20" splittype="stretch"> <statictext> <reportelement x="300" y="0" width="100" height="20"/> <box> <toppen linewidth="0.0"/> <leftpen linewidth="1.0"/> <bottompen linewidth="0.0"/> <rightpen linewidth="1.0"/> </box> <textelement textalignment="center" verticalalignment="middle"> <font isbold="true" isitalic="true"/> </textelement> <text><![cdata[]]></text> </statictext> <statictext> <reportelement x="0" y="0" width="100" height="20"/> <box> <toppen linewidth="0.0"/> <leftpen linewidth="1.0"/> <bottompen linewidth="0.0"/> <rightpen linewidth="1.0"/> </box> <textelement textalignment="center" verticalalignment="middle"> <font isbold="true" isitalic="true"/> </textelement> <text><![cdata[]]></text> </statictext> <textfield> <reportelement x="0" y="0" width="100" height="20"> <printwhenexpression><![cdata[$v{yeargroup_count} == 1]]></printwhenexpression> </reportelement> <box leftpadding="10"> <toppen linewidth="0.0"/> <leftpen linewidth="1.0"/> <bottompen linewidth="0.0"/> <rightpen linewidth="1.0"/> </box> <textelement/> <textfieldexpression><![cdata[$f{year}]]></textfieldexpression> </textfield> <textfield> <reportelement x="200" y="0" width="100" height="20"/> <box leftpadding="10"> <toppen linewidth="1.0"/> <leftpen linewidth="1.0"/> <bottompen linewidth="1.0"/> <rightpen linewidth="1.0"/> </box> <textelement/> <textfieldexpression><![cdata[$f{sum}]]></textfieldexpression> </textfield> <textfield> <reportelement x="100" y="0" width="100" height="20"/> <box leftpadding="10"> <toppen linewidth="1.0"/> <leftpen linewidth="1.0"/> <bottompen linewidth="1.0"/> <rightpen linewidth="1.0"/> </box> <textelement/> <textfieldexpression><![cdata[$f{month}]]></textfieldexpression> </textfield> <textfield evaluationtime="group" evaluationgroup="quatergroup" isblankwhennull="false"> <reportelement stretchtype="relativetobandheight" isprintrepeatedvalues="false" x="300" y="0" width="100" height="20" printwhengroupchanges="quatergroup"> <printwhenexpression><![cdata[$v{quatergroup_count} == 1]]></printwhenexpression> </reportelement> <box leftpadding="10"> <toppen linewidth="0.0"/> <leftpen linewidth="1.0"/> <bottompen linewidth="0.0"/> <rightpen linewidth="1.0"/> </box> <textelement/> <textfieldexpression><![cdata[$v{qsum}]]></textfieldexpression> </textfield> <line> <reportelement x="300" y="0" width="100" height="1" printwhengroupchanges="quatergroup"> <printwhenexpression><![cdata[$v{quatergroup_count} == 1]]></printwhenexpression> </reportelement> </line> </band> </detail> </jasperreport>
the result (in pdf format):
in sample i've used 2 elements in detail
band year
column: 1 textfield
vertical borders , printwhenexpression: "$v{yeargroup_count} == 1"
property (i'm show once whole yeargroup) , 1 statictext
without text , vertical borders.
i've used 3 elements in detail
band quarter sum
column:
1 textfield
vertical borders , printwhenexpression: "$v{quatergroup_count} == 1"
property (i'm show once whole quatergroup), 1 statictext
without text , vertical borders , line
element drawing horizontal border printwhenexpression: "$v{quatergroup_count} == 1"
property.
Comments
Post a Comment