Jump to content

Recommended Posts

Posted

I want to get color to alternate for the groupHeader band in a JasperReports subreport. I have all rows with the same background color but I want it to alternate. Can this be done and if yes, how?

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted

Bands do not have a color attribute.

You would probably have to create two group headers with a print expression one for odd and the other for even pages/records.  Then use a frame in each group header for your coloring.

Another way to do it using the same basic logic as above is with a frame and conditional style.
When it is an even record ($V{REPORT_COUNT} % 2 == 0) then the color from the style should fire else the default color should fire.

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.14.0.final using JasperReports Library version 6.14.0-2ab0d8625be255bf609c78e1181801213e51db8f  --><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="Blank_A4_Landscape" pageWidth="842" pageHeight="595" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="14147cb5-a441-4dbf-9397-a90041afb815">    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="PeimsDS"/>    <property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w1" value="331"/>    <property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w2" value="664"/>    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>    <style name="Alt Coloring" mode="Opaque" backcolor="#FFFFFF">        <conditionalStyle>            <conditionExpression><![CDATA[$V{REPORT_COUNT} % 2 == 0]]></conditionExpression>            <style mode="Opaque" backcolor="#E8B8B7" markup=""/>        </conditionalStyle>    </style>    <queryString>        <![CDATA[sELECT schoolname, lastName, firstName, Address, Countryfrom (    select 'El Dorado HS' as schoolname, 'Smith' as lastname, 'Jane' as firstname, '123 Main St' as Address, 'Canada' as country from dual    union all    select 'El Dorado HS','Smith','Bob','321 Main St','Spain' from dual    union all    select 'El Dorado HS','Smith','Teri','1304 Tyhurst','Canada' from dual    union all    select 'El Dorado HS','Smith','Jose','423 Barbara St','Space' from dual)]]>    </queryString>    <field name="SCHOOLNAME" class="java.lang.String">        <property name="com.jaspersoft.studio.field.name" value="SCHOOLNAME"/>        <property name="com.jaspersoft.studio.field.label" value="SCHOOLNAME"/>    </field>    <field name="LASTNAME" class="java.lang.String">        <property name="com.jaspersoft.studio.field.name" value="LASTNAME"/>        <property name="com.jaspersoft.studio.field.label" value="LASTNAME"/>    </field>    <field name="FIRSTNAME" class="java.lang.String">        <property name="com.jaspersoft.studio.field.name" value="FIRSTNAME"/>        <property name="com.jaspersoft.studio.field.label" value="FIRSTNAME"/>    </field>    <field name="ADDRESS" class="java.lang.String">        <property name="com.jaspersoft.studio.field.name" value="ADDRESS"/>        <property name="com.jaspersoft.studio.field.label" value="ADDRESS"/>    </field>    <field name="COUNTRY" class="java.lang.String">        <property name="com.jaspersoft.studio.field.name" value="COUNTRY"/>        <property name="com.jaspersoft.studio.field.label" value="COUNTRY"/>    </field>    <background>        <band splitType="Stretch"/>    </background>    <columnHeader>        <band height="22" splitType="Stretch">            <staticText>                <reportElement x="11" y="0" width="100" height="16" uuid="7408d444-3aac-4e47-ac60-62c0b78dc671">                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="86cce99b-447a-4214-8124-fa26731175e6"/>                </reportElement>                <box>                    <bottomPen lineWidth="1.0"/>                </box>                <text><![CDATA[sCHOOLNAME]]></text>            </staticText>            <staticText>                <reportElement x="126" y="0" width="100" height="16" uuid="7b5ce5b9-5274-43b2-89cd-7cb6ba739a0d">                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="6b932a47-b9e1-4889-9dde-535afe55587f"/>                </reportElement>                <box>                    <bottomPen lineWidth="1.0"/>                </box>                <text><![CDATA[LASTNAME]]></text>            </staticText>            <staticText>                <reportElement x="241" y="0" width="100" height="16" uuid="f6016038-8138-4229-a1bc-53446d6f6ddc">                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="e6550816-63e6-4953-a5b0-447de08c127d"/>                </reportElement>                <box>                    <bottomPen lineWidth="1.0"/>                </box>                <text><![CDATA[FIRSTNAME]]></text>            </staticText>            <staticText>                <reportElement x="351" y="0" width="100" height="16" uuid="b78a9d07-a664-4cd2-ad87-829266b37810">                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="6d926e78-a369-4a6a-b67b-c770cf20e691"/>                </reportElement>                <box>                    <bottomPen lineWidth="1.0"/>                </box>                <text><![CDATA[ADDRESS]]></text>            </staticText>            <staticText>                <reportElement x="467" y="0" width="100" height="16" uuid="04737ffa-ad85-4cc8-a786-f5daf1db9755">                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="a855fdd6-b977-4173-83a8-af303e6d3dbf"/>                </reportElement>                <box>                    <bottomPen lineWidth="1.0"/>                </box>                <text><![CDATA[COUNTRY]]></text>            </staticText>            <staticText>                <reportElement x="600" y="2" width="189" height="16" uuid="2ab7cacd-012c-4160-8f18-f4d373889dbb">                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="a855fdd6-b977-4173-83a8-af303e6d3dbf"/>                </reportElement>                <box>                    <bottomPen lineWidth="1.0"/>                </box>                <text><![CDATA[bold First, Last (HTML Markup)]]></text>            </staticText>        </band>    </columnHeader>    <detail>        <band height="23" splitType="Stretch">            <frame>                <reportElement style="Alt Coloring" mode="Opaque" x="4" y="0" width="788" height="23" uuid="aa8c37e8-9f2a-490f-baa7-b4e24ac96168"/>                <textField>                    <reportElement x="7" y="6" width="100" height="14" uuid="ca4e0843-b327-4442-a262-cc18d0fd772a">                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="86cce99b-447a-4214-8124-fa26731175e6"/>                    </reportElement>                    <textFieldExpression><![CDATA[$F{SCHOOLNAME}]]></textFieldExpression>                </textField>                <textField>                    <reportElement x="122" y="6" width="100" height="14" uuid="643a7d95-58d8-4a0b-a7d3-355c0766e820">                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="6b932a47-b9e1-4889-9dde-535afe55587f"/>                    </reportElement>                    <textFieldExpression><![CDATA[$F{LASTNAME}]]></textFieldExpression>                </textField>                <textField>                    <reportElement x="237" y="6" width="100" height="14" uuid="05a882e2-8e40-43bc-aa8c-b3f2da01d7ee">                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="e6550816-63e6-4953-a5b0-447de08c127d"/>                    </reportElement>                    <textFieldExpression><![CDATA[$F{FIRSTNAME}]]></textFieldExpression>                </textField>                <textField>                    <reportElement x="347" y="6" width="100" height="14" uuid="f905aa8c-2baa-4ee8-aa4f-fd0ed2bdfe8a">                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="6d926e78-a369-4a6a-b67b-c770cf20e691"/>                    </reportElement>                    <textFieldExpression><![CDATA[$F{ADDRESS}]]></textFieldExpression>                </textField>                <textField>                    <reportElement x="463" y="6" width="100" height="14" uuid="4d931cc1-73cf-4402-a3be-62d4f91110e6">                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="a855fdd6-b977-4173-83a8-af303e6d3dbf"/>                    </reportElement>                    <textFieldExpression><![CDATA[$F{COUNTRY}]]></textFieldExpression>                </textField>                <textField>                    <reportElement x="596" y="3" width="189" height="16" uuid="3a7acd60-54fa-4951-b23c-f6bcb845b637"/>                    <textElement verticalAlignment="Middle" markup="html"/>                    <textFieldExpression><![CDATA["<b>" + $F{LASTNAME} + "</b>," + $F{FIRSTNAME} + "    <sup>®</sup>"]]></textFieldExpression>                </textField>            </frame>        </band>    </detail></jasperReport>[/code]

 

Posted

Thanks jgust but that won't work because the group header can repeat on the same page.

Maybe it helps to provide more detail:

my actual data set delivers

LineItemQuantityAttribute
1A10A1
2B10B1
3A5A1
4A3A2
5B3B1

and I need to group and sum the values based on Item and Quantity so the final output would

LineItemQuantity
1A18
2B13

and I want line 2 to have a different background (yep, using the frame was my plan here) than line 1.

 

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...