Skip to main content
See also: Styles | Columns | Column Groups

How Formatters Work

Formatters provide conditional cell styling based on runtime data. Each formatter is a named array of rules. When a cell renders, Powersheet evaluates each rule’s expression against the current cell context. If the expression returns true, the associated style is applied to that cell. diagram

Formatter Definition

PropertyTypeDefaultDescription
formattersobject{}Top-level section containing named formatter definitions. Each key is a formatter name referenced by columns via the formatter property.
formatters.<name>array[]Array of conditional rules for this formatter. Rules are evaluated in order; all matching rules apply their styles.
formatters.<name>[].expressionstringRequiredJavaScript expression returning a boolean. When true, the associated style is applied to the cell. Has access to the context object.
formatters.<name>[].stylestring or objectRequiredName of a style defined in the styles section, or an inline style object with CSS properties. Applied when the expression evaluates to true.

YAML Structure

formatters:
  formatterName:
    - expression: "context.item.Probability <= 99"
      style: referenceToStylesKey
The formatters section is a root-level key in the sheet configuration, alongside columns, styles, sources, views, columnGroups, renderers, and sortBy.
# Root-level sheet configuration structure
columnGroups: {}
columns: {}
sources: []
renderers: {}
formatters: {}
styles: {}
views: {}
sortBy: []

Expression Context

Every formatter expression has access to the context object. This is the same context available to renderers and dynamic value expressions.
Context PropertyTypeDescription
context.documentobjectThe document data object containing document-level metadata
context.itemobjectThe current entity (row) being rendered. Access entity properties by name, e.g. context.item.Status
context.valueanyThe current cell value for the column being formatted

Expression Types

Formatter expressions support two notation types: Simple boolean expression (recommended):
formatters:
  riskHighlight:
    - expression: "context.item.Probability <= 99"
      style: warningStyle
Inline style object (the style property supports the same CSS properties as Styles):
formatters:
  riskHighlight:
    - expression: "context.item.Severity == 'High'"
      style:
        color: red700
        backgroundColor: red100
        textDecoration: line-through
Complex JavaScript expressions in formatters are not recommended. Keep expressions simple — use straightforward property comparisons and boolean logic. Complex multi-line expressions may cause rendering issues.

Referencing Formatters from Columns

Columns reference formatters by name using the formatter property. The value must match a key defined in the formatters section.
columns:
  severity:
    title: Severity
    width: 120
    formatter: severityFormat

formatters:
  severityFormat:
    - expression: "context.item.Severity == 'Critical'"
      style: darkred
    - expression: "context.item.Severity == 'High'"
      style: red
    - expression: "context.item.Severity == 'Medium'"
      style: orange
    - expression: "context.item.Severity == 'Low'"
      style: green
The formatter column property also accepts an array of formatter names for composing multiple formatting rule sets:
columns:
  title:
    title: Title
    width: 300
    formatter:
      - boldTitle
      - statusHighlight
The formatter value on a column must exactly match a key defined in the formatters section. A mismatched name results in no formatting being applied with no error message.

Unconditional Formatters

A formatter with expression: 'true' always applies its style. This is useful for marking columns as visually distinct without conditions.

Read-Only Column Styling

formatters:
  readonly:
    - expression: 'true'
      style: readOnlyStyle

styles:
  readOnlyStyle:
    backgroundColor: grey100

columns:
  outlineNumber:
    title: "#"
    width: 80
    formatter: readonly
    isReadOnly: true
The isReadOnly column property and formatters serve different purposes. Use isReadOnly: true on a column to prevent editing regardless of formatting. Use a formatter with style: readOnly for visual read-only indication. The isReadOnly value may be overwritten by user permissions or global document configuration.

Bold Title Styling

formatters:
  boldTitle:
    - expression: 'true'
      style: boldTitleStyle

styles:
  boldTitleStyle:
    fontWeight: 600

Conditional Formatters

Conditional formatters evaluate entity properties at render time and apply styles only when conditions are met.

Status-Based Formatting

formatters:
  statusFormat:
    - expression: "context.item.Status == 'Approved'"
      style: green
    - expression: "context.item.Status == 'Draft'"
      style: grey
    - expression: "context.item.Status == 'Rejected'"
      style: red
    - expression: "context.item.Status == 'Obsolete'"
      style: unsupported

columns:
  status:
    title: Status
    width: 120
    formatter: statusFormat

Numeric Threshold Formatting

formatters:
  probabilityFormat:
    - expression: "context.item.Probability > 80"
      style: darkred
    - expression: "context.item.Probability > 50"
      style: orange
    - expression: "context.item.Probability <= 50"
      style: green

Null / Empty Value Formatting

formatters:
  missingValue:
    - expression: "!context.value"
      style: warningStyle

styles:
  warningStyle:
    backgroundColor: orange100
    color: orange700

Multiple Rules per Formatter

A formatter can contain multiple rules. All rules are evaluated in order, and each matching rule applies its style. When multiple rules match, the later rule’s style properties override earlier ones for the same CSS property.
formatters:
  multiRule:
    - expression: "context.item.Priority == 'High'"
      style: red
    - expression: "context.item.IsBlocked == true"
      style:
        textDecoration: line-through
In this example, a high-priority blocked item receives both the red style (background and text color) and the line-through text decoration.

Predefined Styles for Formatters

Formatters reference styles by name. Powersheet provides 20 built-in styles that can be used directly without defining a custom styles section. See Styles for the full list. Commonly used predefined styles with formatters:
Style NameVisual EffectTypical Use
readOnlyRead-only cell indicatorMark non-editable columns
boldTitlefontWeight: 600Emphasize key columns
unsupportedGrey background + line-throughDeprecated or unsupported values
redRed text on light red backgroundHigh severity / critical status
darkredRed text on darker red backgroundVery high severity
orangeOrange text on light orange backgroundMedium severity / warning
darkorangeOrange text on darker orange backgroundElevated severity
greenGreen text on light green backgroundLow severity / approved status
darkgreenGreen text on darker green backgroundConfirmed / verified status
blueBlue text on light blue backgroundInformational highlights
greyGrey text on light grey backgroundInactive or informational
darkgreyGrey text on darker grey backgroundDisabled or archived
tealTeal text on light teal backgroundSecondary categorization
When a formatter references a style name, Powersheet first checks custom styles defined in the styles section, then falls back to built-in styles. A custom style with the same name as a built-in style overrides the built-in.

Row-Level Formatting

Formatters are typically applied at the column level. When a formatter is referenced from a column that spans the full row (such as an outline number column), the visual effect appears to apply to the entire row.
columns:
  outlineNumber:
    title: "#"
    width: 80
    formatter: rowStatus
    isReadOnly: true

formatters:
  rowStatus:
    - expression: "context.item.Status == 'Obsolete'"
      style: unsupported

Interaction with Views

Views can override column properties including the formatter reference. A view can assign a different formatter to a column or remove formatting entirely.
views:
  Simple View:
    columns:
      severity:
        visible: true
  Risk Analysis:
    default: true
    columns:
      severity:
        formatter: severityFormat
        visible: true
The Base View is the state defined by the root columns section. Views extend the Base View by overriding specific column properties. If no views are defined or no default view is specified, the Base View is applied automatically.

Relationship Between Formatters, Styles, and Columns

diagram The three sections work together in a clear chain:
Configuration SectionPurposeReferences
columns.<key>.formatterAssigns a formatter to a columnFormatter name (string or array of strings)
formatters.<name>Defines conditional rules with expressionsStyle name or inline style object
styles.<name>Defines visual CSS propertiesColor tokens (red700, grey100, etc.)

Formatter Naming Conventions

Choose formatter names that describe their purpose. Common patterns in Powersheet configurations:
PatternExamplePurpose
Feature-basedseverityFormatFormat by specific domain property
State-basedstatusHighlightHighlight based on workflow state
Visual intentreadonlyDescribe the visual effect
Entity-scopedhazardSeverityFormat for a specific entity type’s property
CombinedprobabilityWarningProperty name + visual intent

Complete YAML Example

A requirements traceability sheet configuration with formatters for severity, status, and read-only columns using the standard RTM entity hierarchy (UserNeed > SystemRequirement > DesignRequirement > Hazard > RiskControl):
formatters:
  readonly:
    - expression: 'true'
      style: readOnlyStyle

  boldTitle:
    - expression: 'true'
      style: boldTitleStyle

  severityFormat:
    - expression: "context.item.Severity == 'Critical'"
      style: darkred
    - expression: "context.item.Severity == 'High'"
      style: red
    - expression: "context.item.Severity == 'Medium'"
      style: orange
    - expression: "context.item.Severity == 'Low'"
      style: green

  statusHighlight:
    - expression: "context.item.Status == 'Approved'"
      style: green
    - expression: "context.item.Status == 'Draft'"
      style: grey
    - expression: "context.item.Status == 'Rejected'"
      style: red
    - expression: "context.item.Status == 'Obsolete'"
      style: unsupported

  probabilityWarning:
    - expression: "context.item.Probability > 80"
      style: darkred
    - expression: "context.item.Probability > 50"
      style: darkorange
    - expression: "context.item.Probability <= 50"
      style: green

styles:
  readOnlyStyle:
    backgroundColor: grey100

  boldTitleStyle:
    fontWeight: 600

columns:
  outlineNumber:
    title: "#"
    width: 80
    formatter: readonly
    isReadOnly: true

  title:
    title: Title
    width: 300
    hasFocus: true
    formatter: boldTitle

  severity:
    title: Severity
    width: 120
    formatter: severityFormat

  status:
    title: Status
    width: 120
    formatter: statusHighlight

  systemRequirements.systemRequirement.title:
    title: System Requirement
    width: 250
    columnGroup: sysReq

  systemRequirements.systemRequirement.verificationTestCases.verificationTestCase.title:
    title: Verification Test
    width: 200

  hazards.hazard.severity:
    title: Hazard Severity
    width: 130
    formatter: severityFormat

  riskControls.riskControl.probability:
    title: Residual Probability
    width: 140
    formatter: probabilityWarning

columnGroups:
  sysReq:
    groupName: System Requirements
    groupStyle: darkblue
    headerStyle: blue
    collapseTo: systemRequirements.systemRequirement.title

Best Practices

Use predefined styles whenever possible rather than defining custom inline styles. The 20 built-in styles cover most color coding needs. Keep expressions simple. Use straightforward property comparisons (==, <=, >, !) and avoid multi-line or deeply nested JavaScript. Name formatters descriptively. A name like severityFormat is clearer than fmt1 when reviewing configuration. Separate concerns. Define styles in the styles section and reference them from formatters rather than using inline style objects. This promotes reuse across multiple formatters. Order rules intentionally. When multiple rules can match, later rules override earlier ones for the same CSS property. Place higher-priority styles last. ⚠️ Avoid complex expressions. Simple boolean expressions are recommended. Complex JavaScript in formatter expressions may cause unexpected behavior. ⚠️ Do not confuse formatter and render. The formatter property controls cell styling (colors, fonts). The render property controls cell content rendering (custom HTML output). See Render Property.

Conditional Formatting Chain

The full conditional formatting system connects three configuration sections in a chain: the column references a formatter by name, the formatter evaluates expressions and references a style, and the style defines the visual properties. diagram

Style Properties Quick Reference

When defining custom styles for use with formatters, these are the supported CSS properties:
PropertyTypeDefaultDescription
styles.<name>.backgroundColorstringNoneBackground color token (e.g., grey100, red200)
styles.<name>.colorstringNoneText color token (e.g., grey700, red700)
styles.<name>.fontWeightnumberNoneFont weight (e.g., 600)
styles.<name>.textDecorationstringNoneText decoration (e.g., line-through)

All Predefined Styles

All 20 predefined styles can be used in formatter rules without defining them in the styles section:
StyleAppearance
noneNo styling
boldTitleFont weight 600
readOnlyRead-only visual indicator
unsupportedGrey background with strikethrough
grey, darkgreyGrey shades
red, darkredRed shades
orange, darkorangeOrange shades
green, darkgreen, lightgreenGreen shades
blue, darkblue, lightblueBlue shades
teal, darktealTeal shades
purple, darkpurple, lightpurplePurple shades

Decision Matrix: Choosing the Right Approach

RequirementApproachExample
Always apply same styleUnconditional formatter with expression: 'true'Read-only columns
Style based on cell valueConditional expressionSeverity coloring
Color-code column headersUse header.style insteadSee Styles
Color-code column groupsUse groupStyle on column groupSee Column Groups
  • Styles — Named style definitions referenced by formatters
  • Columns — Column configuration including the formatter property
  • Render Property — Custom content rendering (distinct from formatting)
  • Dynamic Value Expressions — Full reference on the context object and expression syntax
  • Views — View-level overrides for column formatting
  • Column Groups — Visual grouping with groupStyle and headerStyle
  • Keyboard Shortcuts — Keyboard navigation in the sheet

Source Code
  • powersheet.yaml
  • whole_rtm.template.yaml
  • PowersheetConfig.d.ts
Authoritative Reference