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

Different Colour For Alternate Rows


swarupap

Recommended Posts

Hi,

 

    I am generating the report in the table format using the organize as table option.Here my requirement is i want to apply different background color for alternate rows.For this i have gone through the forums posted most of them i found is use the rectangle.As they suggested i placed the rectangle in the page footer and set the printwhenexpression to :

new Boolean(($V{REPORT_COUNT} mod 2) == 0)

but when i run the report it is giving the syntax error as "Syntax Error On Token mod Invalid Assignment Operator"

How to resolve this problem.Can you please tell me where i have to place the rectangle component and what properties has to set to get my requirement. Or is there any other simple way in ireport to fulfill my requirement.
 
 
I am using jasperreports-4.5.0
 
 
Thanks IN Advance.
 
 
Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Not sure "mod" is quite right...from the iReport guide on how to do alternating row color:

 

The trick is pretty simple. The first step is to add a frame element in the detail band. The frame will contain all the elements of
the band, so we are using the frame asif it were the background for the band itself; in fact, the frame should take all the space
available in the band. Then all the textfields will be placed inside the frame.


First we define a new style (let's call it Style1). We will keep all the default values, since we are not interested in changing them
when the row number is odd (1, 3, 5, etc...). Now we add a conditional style and set as the condition the expression:


($V{REPORT_COUNT} % 2) == 0


Remember, we have been using Groovy or JavaScript as the report language. In Java the expression would be a bit more
complicated, for example:


($V{REPORT_COUNT}.intValue() % 2) == 0


What the expression does is calculate the rest of the set by 2 (the operator % has this function), and we check if the remainder
is 0. If it is, the current record (held by the REPORT_COUNT built-in variable) is even and we use the conditional style Style1For
this style, we set the background property to a light gray (or any other color of our choice) and the opaque property to true
(otherwise the previous property will not take effect).

Finally, we apply the style to the frame elementby selecting theframe and setting the style property to Style1.

Link to comment
Share on other sites

  • 2 years later...
  • 8 months later...
  • 7 months later...

I tried this out, works great for detail lines.  I have a report where all I am printing in the group footers.  Is there some way I can count like number of footer lines printed?   REPORT_COUNT is telling me the number of detail lines I did not print.

Link to comment
Share on other sites

  • 2 years later...

As per Sudeeps answer above, I was able to put a narrow rectangle with light-gray background color behind my repeating fields (right-click on it, then Order -> Send To Back) , and in the Print When Expression dialog, use his 

$V{REPORT_COUNT}%2==0[/code]

expression to have it appear only on even rows - brilliant.

I tried the earlier suggestion using a frame, but in Jaspersoft Studio (6.6) the band becomes a container for the fields and then making the band visible only on even rows hides the entire set of odd rows, so that doesn't work.

Hopes this helps the next person looking fort this.

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