Get Free Trial
  1. API reference
Connecting to Data Source
Configuring the component
  • Documentation for older versions
  • Table of contents

    Conditional formatting

    Conditional formatting is used to format a cell or a range of cells based on specified criteria. In one report, you can create as many conditions as you need and each condition can apply different formatting rules. Multiple conditional formatting rules for the report will be applied one by one in the order that they were created.

    Conditional formatting rules may be added to all pivot table cells, to the cell specifying row and column indexes, to totals and subtotals only, to regular cells only, or to the cells of the selected measure, hierarchy, and hierarchy’s member.

    Conditions can be defined within a report. When you save the report all the conditional formatting will also be saved and loaded when the report is retrieved.

    To see different live examples on how to use conditional formatting, visit our Examples page.

    More details about conditional formatting are available in the following sections:

    Conditional format properties

    With conditional formatting you can define the following: a logical expression for the rules of the condition (the formula property); style objects for cells that pass the condition (the format property); and the cells to which the condition is applied. Style objects are composed of font size, font color, font family, and background color.

    Here is a list of all available properties for conditions:

    • formula – String. A condition that can contain the following logical operators: AND, OR, ==, !=, >, <, >=, <=, +, -, *, /, isNaN(), !isNaN().
      #value is used as a reference to the cell value in the condition. Example: "#value > 2".
      To refer to another field’s value in the condition, use the field’s name. Example: "'Price' > 2".
    • format – Object. The style object that will be applied to a cell if the condition for the cell value is met. Note: when exporting to Excel and PDF, colors should be set to hex color codes.
    • formatCSS (optional, read-only) – String. Represents a ready to use CSS string of the format style object. The format style object has properties with names that differ from CSS. The component transforms format to formatCSS.
    • id optional – String. The id of the conditional formatting rule. If the id property is not set, the id for the rule will be set inside the pivot component.
    • row optional – Number. The row index to which the condition should be applied.
    • column optional – Number. The column index to which the condition should be applied.
    • measure optional – String. The unique measure name to which the condition should be applied. Must be used with the aggregation property unless the measure is calculated.
    • aggregation optional — String. The aggregation of the measure to which the condition should be applied. If the measure is calculated, skip the aggregation property.
      Not supported for the "microsoft analysis services" data source type.
    • hierarchy optional – String. The unique hierarchy name to which the condition should be applied. Must be used with the member property.
    • member optional – String. The unique member name to which the condition should be applied. Must be used with the hierarchy property.
    • isTotal optional – Boolean. If it is not defined, the condition will be applied to all cells. If it is set to true, the condition will be applied to total and subtotal cells only. If it is set to false, the condition will be applied to regular cells only.

    Style object format

    format is a style object that can have the following properties:

    "format": {
        "backgroundColor": "#FFFFFF",
        "color": "#0000FF",
        "fontFamily": "Arial",
        "fontSize": "12px"
    }

    You can specify only the necessary properties.

    If you want to export the pivot table to Excel and PDF, colors should be set to hex color codes.

    Conditional formatting for all values

    You need to specify the formula and format properties to apply the conditional rule to all values. You can define a format the following way:

    {
        "dataSource": {
            "filename": "https://cdn.flexmonster.com/data/data.csv"
        },
        "conditions": [
            {
                "formula": "#value < 400000",
                "format": {
                    "backgroundColor": "#FFFFFF",
                    "color": "#0000FF",
                    "fontFamily": "Arial",
                    "fontSize": "12px"
                }
            }
        ]
    } 

    Open the example on JSFiddle.

    Conditional formatting for specific values

    A formatting rule can be applied to a specific measure, hierarchy, hierarchy member, column, or row. Additionally, you can apply it only to regular cells or to totals and subtotals. For example, if you are visualizing financial data, you may want to apply conditional formatting only to regular cells with prices. See an example below:

    {
        "dataSource": {
            "filename": "https://cdn.flexmonster.com/data/data.csv"
        },
        "conditions": [
            {
                "formula": "#value < 10000",
                "measure": "Quantity",
                "aggregation": "sum",
                "format": {
                    "backgroundColor": "#7CB342",
                    "color": "#FFFFFF"
                }
            }
        ],
        ...
    } 

    Open the example on JSFiddle.

    Change conditional formatting using the Toolbar

    Go to Format > Conditional formatting in the Toolbar to change/define conditional formatting rules for values at runtime.

    conditionalformatting

    This conditional formatting will be applied to the specified values and will be saved within the report.

    Conditional formatting via API

    The API call addCondition() is used to add or change a conditional formatting rule at runtime. You can change conditions along with other report parts using the API call setReport().