Overview
Problem
The background color of rows/columns can be changed when a certain condition is met, but how to set the table to display alternating row colors?
Solution
You can use the row() formula to obtain the row number (or use the col() formula to obtain the column number) under Condition Attribute > Background to achieve this effect by calculation.
Example one: Background Color Setting Every Other Row
Template Preparation
Open the template Data_Display_Format.cpt in %FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\Primary\DetailReport.
Background Color Setting Every Other Row
Select cell A2, click Condition Attribute on the right side, add a condition, select Background from the drop-down list of Attribute, click Edit, select a color, and select Current Row as the setting range. Select Formula as the formula condition type, click Define, enter the formula row()%2=0, and click Add.
Condition description: row() retrieves the current row number, and %2=0 refers to the number divisible by 2 with a remainder of 0 (the even number). The formula means that the rows with even numbers have a background color while the rows with odd numbers do not have a background color.
The following figure shows the steps.
Effect Display
PC
Save the report and click Pagination Preview. The following figure shows the preview effect.
Mobile Terminal
The template can be previewed on both the DataAnalyst app and the HTML5 terminal. The following figure shows the effect.
Example two: Background Color Setting Every N Rows
You can achieve this effect by modifying the formula in the condition attribute setting of cell A2 in the template used in example one.
Background Color Setting Every N Rows
Modify the former formula to ROUNDUP((ROW()-M)/N,0)%2=0. The following table shows the formula description.
Formula | Description |
---|---|
Row() | To obtain the current row number. |
M | Number of the row where the title is located. |
N | Number of interval rows |
ROUNDUP() | To return a number rounded up, away from zero. |
ROUNDUP((ROW()-M)/N,0)%2=0 | To set a background color for the current row when the rounded up result of dividing the current row number starting from 1 by the number of interval rows N is divisible by 2. |
Select cell A2, define that the N value is 5 as the M value is 1, and modify the formula to ROUNDUP((ROW()-1)/5,0)%2=0 to display the set background color every 5 rows starting from the row where cell A2 is located.
Effect Display
PC
Save the report and click Pagination Preview. The following figure shows the preview effect.
Mobile Terminal
The template can be previewed on both the DataAnalyst app and the HTML5 terminal. The following figure shows the effect.
Example three: Background Color Setting Every Other Group
The following figure shows the result of using the above method in a grouped report.
To set the background color by grouping, you can not set the condition attribute of the grouped cell, but set the condition attribute in the cell to the right of the grouped cells, according to the grouping number to determine whether to display the background color.
Data Preparation
Create a general report, and create a database query ds1 with the SQL statement SELECT * FROM Sales_Volume.
Table Design
Enter the titles into cell A1, cell B1, and cell C1, drag the corresponding data columns into cell A2, cell B2, and cell C2, respectively, select Vertical as Expansion Direction for cell A2, cell B2, and cell C2, and select Group as the Data Setting value for cell A2. The following figure shows the table style.
Background Color Setting
Select cell B2, click Condition Attribute on the right, add a condition, select Background from the drop-down list of Attribute, click Edit, select a color, and select Current Row as the setting range. Select Formula as the formula condition type, click Define, enter the formula &A2%2=0, and click Add.
Condition description: &A2 retrieves the group numbers of the rows expanded from cell A2, and %2=0 refers to the number divisible by 2 with a remainder of 0 (the even number). The formula means that the rows with even group numbers have a background color while the rows with odd group numbers do not have a background color.
The following figure shows the steps.
Effect Display
PC
Save the report and click Pagination Preview. The following figure shows the preview effect.
Mobile Terminal
The template can be previewed on both the DataAnalyst app and the HTML5 terminal. The following figure shows the effect.
Example four: Background Color Setting Every Other Column
This setting works only when columns are expanded from cells horizontally, and the color of expanded header rows will be changed.
You can set the background color every N columns and every N rows in the same way.
Data Preparation
Create a general report, and create a database query ds1 with the SQL statement SELECT * FROM Sales_Volume.
Table Design
Select cell A1, right-click the cell, choose Cell Element > Insert Slash, enter Salesperson |Sales volume |Product, select Diverge from Top Left to Bottom Right, and click OK.
Drag the corresponding data columns into the cells respectively, and set the attribute for each cell, as shown in the following table.
Cell | Data Column | Attribute |
---|---|---|
A2 | Product | Vertical expansion direction and others by default |
B1 | Salesperson | Horizontal expansion direction and others by default |
B2 | Sales volume | No expansion and Summary and Sum selected as the Data Setting value |
The following figure shows the table style.
Background Color Setting Every Other Column
Select cell B1, click Condition Attribute on the right, add a condition, and select Background from the drop-down list of Attribute. Click Edit, select a color, and select Current Row as the setting range. Select Formula as the formula condition type, click Define, enter the formula col()%2=0, and click Add.
Condition description: col() retrieves the current column number, and %2=0 refers to the number divisible by 2 with a remainder of 0 (the even number). The formula means that the columns with even numbers have a background color while the columns with odd numbers do not have a background color.
The following figure shows the steps.
Effect Display
PC
Save the report and click Pagination Preview. The following figure shows the preview effect.
Mobile Terminal
The template can be previewed on both the DataAnalyst app and the HTML5 terminal. The following figure shows the effect.