Skip to main content

Prerequisites

  • Admin access to modify risksheet.json (canAdmin must be true)
  • Familiarity with the configuration editor
  • Basic understanding of CSS properties (background-color, color, font-weight)

How Conditional Formatting Works

Conditional formatting in Risksheet uses a two-part system:
  1. cellDecorators --- JavaScript functions that evaluate cell data and toggle CSS classes on the cell element
  2. styles --- CSS class definitions that control the visual appearance applied by decorators
The decorator function runs every time a cell is rendered. It receives the cell’s value and the full row data, then adds or removes CSS classes based on conditions you define. The styles section injects those CSS classes into the page, controlling colors, fonts, and other visual properties. diagram

Step 1: Define CSS Styles

Add named CSS class definitions to the styles object in your risksheet.json. Each entry maps a CSS class selector to a string of CSS properties. The class name must start with a dot (.), and the CSS properties must be wrapped in curly braces.

RPN Threshold Styles

This example defines a three-tier color scheme for Risk Priority Number values:
{
  "styles": {
    ".boldCol": "{font-weight:600;}",
    ".rpn1": "{background-color: #eaf5e9 !important;color: #1d5f20 !important;}",
    ".rpn2": "{background-color: #fff3d2 !important; color: #735602 !important;}",
    ".rpn3": "{background-color: #f8eae7 !important;color: #ab1c00 !important;}"
  }
}
CSS ClassVisual EffectTypical Use
.boldColBold text (font-weight: 600)Emphasize computed columns
.rpn1Green background, dark green textLow risk (RPN 1—150)
.rpn2Amber background, dark amber textMedium risk (RPN 151—350)
.rpn3Red background, dark red textHigh risk (RPN > 350)
Risksheet applies default grid styles that override custom styles without !important. You must include !important on background-color and color properties in the styles object. Without it, your conditional formatting colors will not appear.

Header Group Styles

You can also define styles for column group headers using compound selectors:
{
  "styles": {
    ".firstRow .headSysReq": "{background-color:rgba(62, 175, 63, 0.12) !important;color:#2A792D !important}",
    ".lastRow .headSysReq": "{background-color:#FFF !important;color:#2A792D !important}",
    ".firstRow .headFinalRanking": "{background-color:rgba(62, 175, 63, 0.12) !important;color:#2A792D !important}",
    ".lastRow .headFinalRanking": "{background-color:#FFF !important;color:#2A792D !important}"
  }
}
These compound selectors apply different colors to the first and last rows of header groups, creating a gradient effect in multi-row column headers.

Step 2: Create Cell Decorator Functions

Add JavaScript functions to the cellDecorators object. Each decorator is keyed by the column binding it targets. The function receives an info object and uses jQuery’s toggleClass method to conditionally apply CSS classes.

RPN Column Decorator

{
  "cellDecorators": {
    "rpn": "function(info){ var val = info.value; $(info.cell).toggleClass('boldCol', true); $(info.cell).toggleClass('rpn1', val>0 && val <= 150); $(info.cell).toggleClass('rpn2', val > 150 && val <= 350); $(info.cell).toggleClass('rpn3', val > 350);}"
  }
}
This decorator:
  1. Always applies boldCol (the second argument true means “always add”)
  2. Applies rpn1 only when the value is between 1 and 150
  3. Applies rpn2 only when the value is between 151 and 350
  4. Applies rpn3 only when the value exceeds 350
  5. When a condition is false, toggleClass removes that class, ensuring only one threshold class is active at a time

Row Header Decorator

You can also apply conditional formatting to row headers using the headers.rowHeader.renderer property. The row header decorator accesses data from the entire row:
{
  "cellDecorators": {
    "rowHeaderRpnNew": "function(info){ var val = info.item['rpnNew']; $(info.cell).toggleClass('rpn1', val>0 && val <= 150); $(info.cell).toggleClass('rpn2', val>0 && val > 150 && val <= 350); $(info.cell).toggleClass('rpn3', val>0 && val > 350);}"
  },
  "headers": {
    "rowHeader": {
      "renderer": "rowHeaderRpnNew"
    }
  }
}
This colors the entire row header based on the revised RPN value, giving an immediate visual indicator of each risk item’s current risk level.

The info Object in Cell Decorators

PropertyTypeDescription
info.valueanyThe current cell’s display value after formula execution
info.cellDOM elementThe cell’s HTML element (jQuery-wrapped via $(info.cell))
info.itemobjectThe full row data object with all column bindings as keys

Enum Value Decorator

When decorating cells that contain enum values, compare against the enum ID (the internal identifier), not the display name:
{
  "cellDecorators": {
    "completionStatus": "function(info){ var val = info.value; $(info.cell).toggleClass('statusGreen', val === 'yes'); $(info.cell).toggleClass('statusRed', val === 'no'); $(info.cell).toggleClass('statusAmber', val === 'partial');}"
  }
}
Cell decorator functions receive the internal enum ID as the value, not the display name. For example, if your enum has id: "yes" with name: "Y", the decorator must compare against 'yes', not 'Y'. Comparing against display values is a common mistake that causes conditional formatting to never activate.
If you want enum descriptions to appear in dropdown menus alongside the name, use type: 'rating:ENUMID' instead of type: 'enum:ENUMID'. Regular enum columns show only the name; rating columns show both name and description. This does not affect how decorators receive the value --- both types pass the enum ID.

Step 3: Apply Static Column Styles

For columns that should always have a specific style (not conditional), use the cellCss property on the column definition instead of a decorator:
{
  "columns": [
    {
      "id": "rpn",
      "header": "RPN",
      "binding": "rpn",
      "formula": "commonRpn",
      "cellCss": "boldCol"
    }
  ]
}
The cellCss property applies the named CSS class to every cell in the column unconditionally. Use it for:
  • Making all cells in a column bold
  • Applying a fixed background color to a column group
  • Adding a border or padding to specific columns
Combine cellCss for static styles with cellDecorators for dynamic, value-based styles on the same column.

Step 4: Highlight Mandatory Fields Visually

Risksheet intentionally does not enforce Polarion mandatory field validation during data entry (to make risk entry faster). Instead, use conditional formatting to visually indicate which fields require values:
{
  "cellDecorators": {
    "severity": "function(info){ var val = info.value; $(info.cell).toggleClass('requiredEmpty', !val || val === ''); $(info.cell).toggleClass('requiredFilled', val && val !== '');}"
  },
  "styles": {
    ".requiredEmpty": "{background-color: #fff8e1 !important; border-left: 3px solid #ff9800 !important;}",
    ".requiredFilled": "{border-left: none;}"
  }
}
Since Risksheet does not enforce Polarion mandatory fields by design (to simplify data entry), use cell decorators and styles to highlight empty required columns with a colored background or border. This provides a visual cue without blocking the user’s workflow.

Complete Configuration Example

Here is a full risksheet.json excerpt combining formulas, decorators, and styles for an FMEA risk analysis sheet:
{
  "formulas": {
    "commonRpn": "function(info){ var value = info.item['occ']*info.item['det']*info.item['sev']; return value?value:null;}",
    "commonRpnNew": "function(info){ var value = info.item['occNew']*info.item['detNew']*info.item['sevNew']; return value?value:null; }"
  },
  "cellDecorators": {
    "rpn": "function(info){ var val = info.value; $(info.cell).toggleClass('boldCol', true); $(info.cell).toggleClass('rpn1', val>0 && val <= 150); $(info.cell).toggleClass('rpn2', val > 150 && val <= 350); $(info.cell).toggleClass('rpn3', val > 350);}",
    "rpnNew": "function(info){ var val = info.value; $(info.cell).toggleClass('boldCol', true); $(info.cell).toggleClass('rpn1', val>0 && val <= 150); $(info.cell).toggleClass('rpn2', val > 150 && val <= 350); $(info.cell).toggleClass('rpn3', val > 350);}",
    "rowHeaderRpnNew": "function(info){ var val = info.item['rpnNew']; $(info.cell).toggleClass('rpn1', val>0 && val <= 150); $(info.cell).toggleClass('rpn2', val>0 && val > 150 && val <= 350); $(info.cell).toggleClass('rpn3', val>0 && val > 350);}"
  },
  "styles": {
    ".boldCol": "{font-weight:600;}",
    ".rpn1": "{background-color: #eaf5e9 !important;color: #1d5f20 !important;}",
    ".rpn2": "{background-color: #fff3d2 !important; color: #735602 !important;}",
    ".rpn3": "{background-color: #f8eae7 !important;color: #ab1c00 !important;}",
    ".firstRow .headSysReq": "{background-color:rgba(62, 175, 63, 0.12) !important;color:#2A792D !important}",
    ".lastRow .headSysReq": "{background-color:#FFF !important;color:#2A792D !important}",
    ".firstRow .headFinalRanking": "{background-color:rgba(62, 175, 63, 0.12) !important;color:#2A792D !important}",
    ".lastRow .headFinalRanking": "{background-color:#FFF !important;color:#2A792D !important}"
  },
  "headers": {
    "rowHeader": {
      "renderer": "rowHeaderRpnNew"
    },
    "columnHeader": {
      "height": 32
    },
    "columnGroupHeader": {
      "height": 32
    }
  }
}

Verification

After applying conditional formatting, you should now see:
  1. ✅ RPN cells display with green, amber, or red backgrounds based on their computed values
  2. ✅ Row headers change color to match the revised RPN risk level
  3. ✅ Bold text appears on formula columns with the boldCol class
  4. ✅ Colors update automatically when risk parameter values change
  5. ✅ Conditional formatting is preserved in Excel exports (via includeStyles)
The exact appearance of conditional formatting may vary depending on your browser, Polarion theme, and any custom CSS injected at the project level. Test your decorator functions with representative data covering all threshold ranges.

See Also

KB ArticlesSupport TicketsSource Code
  • AppConfig.ts
  • risksheet.json
  • CellPreviewFormatter.ts
  • CellEditorFormatter.ts
  • ExportToPdf.ts