1
votes

Is it possible to implement something like rowSpan with jasperrepors textfileds?

I have two reports: main and subreport.

In main detail band i have textfield and subreport:

<band height="15" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
    <reportElement style="cell" stretchType="RelativeToBandHeight"
                   x="20" y="0" width="200" height="15"
                   isPrintWhenDetailOverflows="true"/>
    <textElement textAlignment="Center" verticalAlignment="Middle">
        <font fontName="DejaVu Sans" size="7" isBold="true"/>
        <paragraph leftIndent="1" rightIndent="1" spacingBefore="1"
                   spacingAfter="1"/>
    </textElement>
    <textFieldExpression><![CDATA[$F{org_name}]]></textFieldExpression>
</textField>
<subreport>
    <reportElement stretchType="RelativeToTallestObject" x="220" y="0"
                   width="582" height="15" isPrintWhenDetailOverflows="true">
        <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
    </reportElement>
    <subreportParameter name="SUBREPORT_DIR">
        <subreportParameterExpression>
            <![CDATA[$P{SUBREPORT_DIR}]]>
        </subreportParameterExpression>
    </subreportParameter>
    <dataSourceExpression><![CDATA[$F{EDU_LEVEL_DATASOURCE}]]></dataSourceExpression>
    <subreportExpression>
        <![CDATA[$P{SUBREPORT_DIR}
                 + "/reports/scholarship_fund_analysis/sub_education_level.jasper"]]>
    </subreportExpression>
</subreport>

And there is one textfield in subreport's detail band.

The purpose is to implement something like rowSpan for "org_name" textField in main report. It works fine when subreport has a lot of content.

The problem arises when org_name is too long, and subreport has few rows. The height of org_name textfield is greater than total height of subreport. And there is empty space under subreport until next row of main report.

Result report looks like this:

textfield and subreport

1

1 Answers

0
votes

Idea: pass parameter containing text of first column from report to subreport. In subreport, display this parameter in background band with font color #FFFFFF (white).

How to do it

My report structure: how it looks before

First column is in main report ($F{daysLabel}). Second and third column in subreport.

Create parameter in main report (select subreport, 1, and then Edit Parameters, 2, as shown below)

how enter a parameter

(I have less than 10 points reputation, I may not put more image links, so no more images.)

In the window that opens you enter the parameter name (let's say toto) and under expression, you enter the variable holding the value of your column, in my case $F{daysLabel}.

In the subreport you create a parameter with the same name as the one you just created in the main report (toto) and you display it in the background band. Set the stretch overflow condition to true. In my case this is ok since the width of the first column fits perfectly in my subreport witdh. Maybe in your case you might need to do a "special tunning".

Set the color font to white and you'll see your subreport stretching as much as the first column of your main report. As for the borders of your cells in the subreport, set the bottomPen to 0:

<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>

so that only the upper border is visible.

In your main report, surround your subreport with a frame having all 4 borders.

My comment (if you mind): it's a nasty way, I think. At the same time, I believe jasper's engine renders from the innermost subreport to the outermost, i.e. the main report. Once jasper is done with the outermost report, it doesn't re-render the inner reports to adjust to the outermost. I've tried with evaluation time other than Now and Auto but the text fields do not stretch anymore. I've also tried different stretch types in main and sub-report with no luck. This is the only solution I could figure out.

I'd be very happy to see if some has got a cleaner solution to this problem.