Subreports with alternating backgrounds

338 views Asked by At

I'm using iReport 3.7.6. (with no possibility of using a newer version).

I have a main report and a subreport. Subreport repeats multiple times and I need to set alternating background to subreports, but I need to show subreports one below each other so that they split when the new page starts, not showing them on page only if they fit.

This is what I want: enter image description here

I tried multiple things but I cannot seem to get it to work.

I tried using frame and setting alternate row style and putting all the elements in that frame:

<style name="AlternateRowStyle" mode="Opaque">
    <conditionalStyle>
        <conditionExpression><![CDATA[$V{REPORT_COUNT} % 2 == 0]]></conditionExpression>
        <style backcolor="#E5E7E9"/>
    </conditionalStyle>
</style>

but I get results like in this post: Splitting a band's background frame

Then I tried using background band (for simplicity, I just added frame with one color, so no alternation) but I have experienced difficulties in this approach too.

My subreport has only Detail and Background band to which I've set equal height and split type immediate.

Main report only has detail band (I simplified it).

Subreport snippet:

<background>
    <band height="250" splitType="Immediate">
        <frame>
            <reportElement mode="Opaque" x="0" y="0" width="600" height="250" backcolor="#E5E7E9"/>
        </frame>
    </band>
</background>
<detail>
    <band height="250" splitType="Immediate">
        //content not important
    </band>
</detail>

Main report snippet:

<detail>
    <band height="660" splitType="Immediate">
        <subreport>
            <reportElement positionType="Float" x="0" y="0" width="600" height="250"/>
            <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{objects})]]></dataSourceExpression>
            <subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "subreport1.jasper"]]></subreportExpression>
        </subreport>
    </band>
</detail>

But this approach results in wierd behaviour: Background from subreport shows on each page of main report only once and only at the beginning of the page, no matter how many subreports are actually on one page of main report, like background is set to main report (shown on picture). I would like each report to have the background.

enter image description here

I'd appreciate any help.

0

There are 0 answers