Ask Reuben

RepeatingRegion Class

In a report, how do I give a different background color to alternate rows?

A technique to better read values across rows when there are many columns is to render alternate rows with a different background color.  In Genero screens, this can be achieved with the alternateRows Presentation Style attribute.  In printing, this was historically achieved with the iconic green bar paper.  With more modern printers using blank A4 paper, this would mean using ink to render the different background colors and fell out of fashion.  In todays world, reports are rarely physically printed out on paper and more typically viewed on screen, and so the requirement to print alternate rows with a different background color is back in fashion.

Up until Genero Report Writer 5.00, to determine what rows to apply a different background color has typically required coordination between the 4gl team and the reporting team.  You need the 4gl to be including in the report datastream, a row counter.  The report designer designs the report to have different background color depending if this row counter was odd or even.  This approach had a significant failing.  If the report design required a row to be hidden, for instance hide a row if a quantity value is zero, then you would end up in a situation where two odd or two even rows were adjacent to each other and would get the same background color.

What was needed was a solution that was independent of any values in the datastream.  If a repeated design element was visible, we needed to give this repeated design element an index value.  This is achieved in GRW 5.00 with the new  “RepeatingRegion” class.  The RTL expression …

getRepeatingRegion().getGlobalIndex(), getRepeatingRegion.getLocalIndex()

… would return a counter (starting at 0) for the repeating region, and then it is simply a case of doing a MOD 2 (%2) to determine if this is an odd or even instance of the repeating region.  An RTL expression for the background color of a row such as …

getRepeatingRegion().getGlobalIndex()%2==1?Color.fromRGBA(192,192,192,0):null

… can then be used to render every second row with a grey background.

‘This can be seen in the OrderList.4rp demo from OrderReport in Tutorials & Samples.  If you find the “Data Row” report object that is the first child of the “On Every Row” trigger, you will see that its “Background Color” property has an RTL expression that starts getRepeatingRegion …

.. and produces a report where every second row has a grey background as pictured below.

If you are physically printing reports you are unlikely to use this class,  but for reports that you email or display on screen then this technique can aid the readability of the report.