Alternate colors of odd and even rows

You can alternate the background color of the rows in a table or list. For example, you could use a grey background for odd-numbered rows and a white background for even-numbered rows.

About this task

You create a variable to number the rows, and use this variable to distinguish odd from even rows.

  1. In the BDL for your report, specify a variable that increments by 1 for each new row.

    For example:

     ...
    
     DEFINE row_id INTEGER
     LET row_id = 0
     ...
    
        START REPORT myReport 
        FOREACH c_order INTO orderline.*
            OUTPUT TO REPORT myReport(orderline.*, row_id)
            LET row_id=row_id+1
            ...
        END FOREACH
        FINISH REPORT myReport
     
      ...
    
  2. Generate the data schema (see Generate a data schema from a Genero BDL report program).
    The new data field (for example, row_id) displays in your Data View.
  3. Open the Report Design Document. In the Table or List, select the row, and edit the Background Color property to specify the color of the alternating rows.

    For example, to set odd-numbered rows to grey and even-numbered rows to the default color:

    row_id%2==0?Color.LIGHT_GRAY:null

The Table or List displays similar to Figure 1.

Figure: Table with alternating colors

This figure is a screenshot of a Table with rows that alternate background colors. Odd-numbered rows are grey, while even-numbered rows are white.