New to Telerik Reporting? Download free 30-day trial

Alternating the Cell Background Color by Table Group

Environment

Product Progress® Telerik® Reporting

Description

What conditional formatting can I use to alternate the detail cell background color based on table groups?

Cause

For alternating detail rows in a table, I use conditional formatting based on the following Expression and set different colors for odd and even rows:

RowNumber()%2

The % is the remainder after the division operator. Then, I set the Expression to depend on the group:

=RowNumber('groupName')%2

However, in the group, the row numbers increase within the group. That's why the color will alternate within the group rows, whereas my requirement is the rows of each group to have the same color and for this color to change between groups.

Solution

To handle the issue, use the following Expression:

=RunningValue("tableName", CountDistinct(Fields.groupingFieldName))%2

The RunningValue data function assures that only the values up to the current one get respected. The CountDistinct aggregate function counts the distinct grouping values, in this case, up to the current one. This approach will leave 1 for the first group, 2 for the second, and so on. Hence, the Expression will return 0 for the even groups within the table and 1 for the odd ones.

In this article