Jump to content
We've recently updated our Privacy Statement, available here ×

Zebra stripping in jasperreports using groups not rows


gustavofarias
Go to solution Solved by szaharia,

Recommended Posts

There are lots of tutorials on how to zebra stripe the rows of a report. Like this:

 

    Value Color

    A white

    A black

    B white

    B black

    B white

    C black

    D white

    D black

 

But what I want to do is a grouped stripping. Like this:

 

    Value Color

    A white

    A white

    B black

    B black

    B black

    C white

    D black

    D black

 

I'm using the column "Value" as the expression of a group and my data is sorted by "Value". "black" is a black rectangle to be printed when the group is black. "white" is the absence of the black rectangle. I want a variable that I can put in "Print When Expression" of the black rectangle.

 

What I've tried until now:

 

 - Create a variable $V{print}

 - Initial Value Expression: false

 - Variable Expression: !$V{print}

 - Increment type: Group

 - Increment group: Value

 

I expected the value of $V{print} to change to it's opposite value every time the group changed. What I get is the normal striped list (black, white, black, white...)

Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution

Hello,

Try the following:

Create a variable $V{print} of type java.lang.Integer
- Variable Expression: Boolean.TRUE
- Variable calculation: Count
- Increment type: Group
- Increment group: Value

Then create a conditional style with desired background features, and set the following condition expression:
$V{print}%2 == 1
Use this style for elements in detail band, instead of printing an overlapping rectangle  with printWhenExpression.

I hope this helps,
Sanda

Link to comment
Share on other sites

I think the reason why my attempt didn't work is this:

JasperReports Schema Reference: "incrementType: Increment level for variables that perform calculations"

As the Calculation was "none", the group increment was ignored and the expression was being evaluated every iteration.

 

I think there is some confusion in documentation:

reference 1) JasperReports Schema Reference: "incrementType: Increment level for variables that perform calculations"

reference 2) The JasperReports Ultimate Guide: INCREMENT TYPE: This property lets you choose the exact moment to increment the variable....

reference 3) iReport property comment: Increment Type: When the variable expression should be evaluated to get a new value.

 

Reference 2 and 3 agree with one another and basically ignores what is said in reference 1, which is the correct one. Based solely on references 2 and 3, my original solution should work. 

Link to comment
Share on other sites

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...