Background Color Setting Every Other Row/Column

  • Last update:April 28, 2025
  • 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.

    行列1.png 

    Effect Display

    PC

    Save the report and click Pagination Preview. The following figure shows the preview effect.

     行列2.png

    Mobile Terminal

    The template can be previewed on both the DataAnalyst app and the HTML5 terminal. The following figure shows the effect.

    12.png 

    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.

    FormulaDescription
    Row()To obtain the current row number.
    MNumber of the row where the title is located.
    NNumber of interval rows
    ROUNDUP() To return a number rounded up, away from zero.
    ROUNDUP((ROW()-M)/N,0)%2=0To 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.

    行列3.png

    Effect Display

    PC

    Save the report and click Pagination Preview. The following figure shows the preview effect.

     行列4.png

    Mobile Terminal

    The template can be previewed on both the DataAnalyst app and the HTML5 terminal. The following figure shows the effect.

     13.png

    Example three: Background Color Setting Every Other Group

    The following figure shows the result of using the above method in a grouped report.

     行列5.png

    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.

     行列6.png

    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.

     行列7.png

    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.

     行列9.png

    Effect Display

    PC

    Save the report and click Pagination Preview. The following figure shows the preview effect.

     行列8.png

    Mobile Terminal

    The template can be previewed on both the DataAnalyst app and the HTML5 terminal. The following figure shows the effect.

    行列11.jpg 

    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.

     行列6.png

    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.

     行列12.png

    Drag the corresponding data columns into the cells respectively, and set the attribute for each cell, as shown in the following table.

    CellData ColumnAttribute
    A2  ProductVertical expansion direction and others by default
    B1SalespersonHorizontal expansion direction and others by default
    B2Sales volumeNo expansion and Summary and Sum selected as the Data Setting value

    The following figure shows the table style.

     行列13.png

     

    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.

    行列14.png 

    Effect Display

    PC 

    Save the report and click Pagination Preview. The following figure shows the preview effect.

     行列15.png

    Mobile Terminal

    The template can be previewed on both the DataAnalyst app and the HTML5 terminal. The following figure shows the effect.

     行列16.jpg

    Template Download

    Attachment List


    Theme: Report Features
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy