How to merge multiple rows in report? - jasper-reports

I wanted to merge multiple rows in JasperReports's report without using crosstab. Is it achievable?
Here I have pasted my jrxml code for removing duplicate printing, but it keep lines around the cell although there is no record inside.
<textField pattern="dd.MM.yyyy" isBlankWhenNull="true">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="110" height="21" isRemoveLineWhenBlank="true"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{DEPARTURE_DATE}]]></textFieldExpression>
</textField>

Related

How to combine two textFields into one box in RTF generated by Jasper reports?

I use Jasper Reports to generate RTF file.
In RTF each textField is represented as separate box:
I tried to use one frame for textFields:
<frame>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="220" y="45" width="406" height="75"/>
<textField>
<reportElement positionType="Float" x="0" y="0" width="406" height="60"/>
<textElement>
<font fontName="Arial" size="8"/>
</textElement>
<textFieldExpression><![CDATA["Address:"]]></textFieldExpression>
</textField>
<textField hyperlinkType="Reference" hyperlinkTarget="Blank">
<reportElement x="0" y="57" width="200" height="15" key="textWithStyle" style="LinkField"/>
<textElement>
<font fontName="Arial" size="8" isUnderline="true"/>
</textElement>
<textFieldExpression><![CDATA["here"]]></textFieldExpression>
<hyperlinkReferenceExpression><![CDATA["http:adress"]]></hyperlinkReferenceExpression>
</textField>
</frame>
But textFields also in the different boxes.
Is it possible to combine several textFields into one box like the following?
I know that I can add each text to one textField, but sometimes I need two separate textFields that I can manage inside one box.

different pages on change of group in jasper reports

My report groups contains 4-5 table component which will be printed each time when group changed.I don't want to print multiple entries of same group in the table components inside the group.
<textField>
<reportElement x="150" y="0" width="60" height="20" isPrintRepeatedValues="false" />//**isPrintRepeatedValues="false"**
<textElement textAlignment="Left">
<font isBold="false" isUnderline="false"/>
</textElement>
<textFieldExpression><![CDATA[$F{activityname}]]></textFieldExpression>
</textField>
<textField>

How to split column headers and detail across two or more pages

We are building a dynamic report designer that is based on JasperReports. For the most part, we use PDF as the default output.
We are facing a serious problem where, for example, if a user selects eight columns in a report, it may be that the only way to print the report is so that the first 4 columns detail and headers show on the first page and the last 4 column detail and headers show on a second page.
It looks like column breaks are the way to do this and I've been trying them in Jasper Reports, but with no luck. Below I've added the detail band in a jrxml file where I'm trying to use the break element to break to a new page after the third column. I'm trying to use a printWhenExpression on the column break to break before the fourth column.
Note that while this test case is small and really doesn't need a break other reports that are being created have 20+ columns that need to be spread across 3 or more pages.
<detail>
<band height="16" splitType="Stretch">
<textField isBlankWhenNull="true">
<reportElement x="24" y="1" width="100" height="15" uuid="4bb1d713-2c34-42e9-aeb4-63aa41d10060"/>
<textFieldExpression><![CDATA[$F{L_BUILDING_CODE}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="140" y="1" width="100" height="15" uuid="9d55a9e3-fa9f-497b-b744-dd853ac21a4a"/>
<textFieldExpression><![CDATA[$F{L_BUILDING_NAME}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="250" y="1" width="100" height="15" uuid="e70b4bc4-a8a7-4e97-abdc-e58346daa002"/>
<textFieldExpression><![CDATA[$F{L_CITY}]]></textFieldExpression>
</textField>
<break type="Column">
<reportElement key="" x="0" y="1" width="250" height="1" uuid="3bf6f2c0-a0d6-43dd-9d3f-ddd1e46d5fc7" >
<printWhenExpression><![CDATA[$V{COLUMN_NUMBER}.intValue() == 4]]></printWhenExpression>
</reportElement>
</break>
<textField>
<reportElement x="600" y="1" width="100" height="15" uuid="19cb12e8-6474-4776-a9fa-2c7d34e69573"/>
<textFieldExpression><![CDATA[$F{L_STATE_PROVINCE}]]></textFieldExpression>
</textField>
</band>
</detail>
Can someone show me an example of how to do this?

How do I hide a table column based on its content?

I have a report which contains a table. I would like to hide the columns of that table based on the result set of the query that backs the table. As an example, here is the XML for one of the columns:
<jr:column width="80">
<printWhenExpression>$F{Total1_header} != null</printWhenExpression>
<jr:columnHeader height="30" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="80" height="30" style="table_CH"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression>$F{Total1_header}</textFieldExpression>
</textField>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="80" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression>$F{Total1}</textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
For some reason, my report is complaining about the printWhenExpression. It claims that $F{Total1_header} does not exist. It does not complain however about the instance of $F{Total1_header} in the textFieldExpression.
I can't figure out why the field is avaiable for the textFieldExpression, but not the printWhenExpression.
Column has 'Column print when' property to hide/show the column by an expression.
Another way to delete columns is to modify the jasper design at runtime, then report compilation and then procees as usually. This method makes it possible to distribute unused width to remaining columns.
Roughly goes like this:
JasperDesign design = ...
JRDesignComponentElement tableElement = (JRDesignComponentElement) design.getTitle().getElementByKey(tableKey);
StandardTable tableComponent = (StandardTable) tableElement.getComponent();
col = tableComponent.getColumns().get(0);
tableComponent.removeColumn(col);
// Then compile the JasperDesign
JasperReport result=JasperCompileManager.compileReport(design);
For future readers
You should use this
<printWhenExpression><![CDATA[$F{Total1_header} != null]]></printWhenExpression>
Instead of
<printWhenExpression>$F{Total1_header} != null</printWhenExpression>

stretch a row to fit the data in jasper reports using iReport

How do i stretch a text field to fit the data, If data exceeds the band height the text field doesn't stretch. I have added the text field tag in my jrxml...
The example:
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
style="dNew"
mode="Opaque"
x="200"
y="0"
width="200"
height="19"
key="value-2"
stretchType="RelativeToTallestObject"
positionType="Float"
isPrintInFirstWholeBand="true"
isPrintWhenDetailOverflows="true"/>
<box></box>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Arial" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{DATA2}]]></textFieldExpression>
</textField>
Some bands do not stretch, but if you are talking about the detail band you can do something like this:
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="base" positionType="Float"
isPrintRepeatedValues="false" x="0" y="3"
width="380" height="26" isRemoveLineWhenBlank="true"/>
<textElement/>
<textFieldExpression class="java.lang.String">
<![CDATA[$P{information}]]></textFieldExpression>
</textField>
That is pasted from auto generated XML so there is a lot of extra stuff, but the isStretchWithOverflow="true" should work for you. This will make the field stretch down as the text fills it up.
I ususally use iReport to build my reports and it works quiet nicely. You can switch to an XML view in there too.