For the complete documentation index, see llms.txt. This page is also available as Markdown.

Apply Conditional Cell Styling

Tint table cells with SLDS classes, either the same style on every row or a style picked per row by a formula field, so key values stand out.

A sales operations lead scans a long pipeline table and wants the Stage cells tinted like a spreadsheet: shaded for early deals, orange near the close, green for won, red for lost. Each column has an SLDS Cell Class setting. Type classes into it to style every row the same way, or bind it to a formula field to pick the style row by row.

Data Table of opportunities where each Stage cell has a background color matching its stage, and amounts are bold.
Stage cells take their SLDS classes from the Stage Style formula field.

Before you start

  • A Data Table on Opportunity with a Query data source, showing at least the Opportunity Name, Stage and Amount columns.

  • Permission to create a formula field on Opportunity (Customize Application).

Steps

1

Create the Stage Style formula field

The formula returns the SLDS classes to apply to each row's cell. It uses the same stage groups as Apply Badge Color-Coding and Add Status Indicators.

  1. In Setup, open Object Manager, then Opportunity, then Fields & Relationships, and click New.

  2. Choose Formula, name the field Stage Style, and set the return type to Text.

  3. Paste this formula, then save:

Any other stage returns an empty value and keeps the default cell style.

2

Open the column's Cell Attributes

  1. Select the Data Table on the canvas.

  2. In the Properties panel, open the Data Mappings section and click the Stage column in the Columns list.

  3. Scroll to Cell Attributes and find SLDS Cell Class.

3

Bind SLDS Cell Class to the formula field

  1. Turn on the Field Name toggle at the top right of SLDS Cell Class.

  2. Select Stage Style in the field list.

You do not need a column for Stage Style. The table fetches a bound field on its own.

Cell Attributes of the Stage column with SLDS Cell Class bound to the Stage Style field.
SLDS Cell Class bound to the formula field with the Field Name toggle.
4

Save and test

Save the component and open the page that holds it. The Stage cell of a Prospecting deal is shaded gray, a Negotiation/Review deal is light orange, a Closed Won deal is light green and a Closed Lost deal is pink. Theme classes tint the whole cell and adjust its text color. The other columns keep their default style.

Same style on every row

When the style does not depend on the record, skip the formula. Leave the Field Name toggle off and type the classes into SLDS Cell Class, separated by spaces. For example, slds-text-title_bold on the Amount column bolds every amount.

SLDS classes for cell styling

These are standard Salesforce Lightning Design System utility classes. Combine several with a space, for example slds-theme_shade slds-text-title_bold.

Class
Effect

slds-theme_shade

Light gray background

slds-theme_info

Light blue background

slds-theme_warning

Light orange background

slds-theme_success

Light green background

slds-theme_error

Pink background

slds-theme_inverse

Dark blue background

slds-theme_alert-texture

Striped texture, added on top of a background class

slds-text-color_weak

Gray text

slds-text-color_success

Green text

slds-text-color_error

Red text

slds-text-color_inverse

White text, for dark backgrounds

slds-text-title_caps

Small uppercase text

slds-text-title_bold

Bold text

SLDS Cell Class takes class names, not colors. To use your own hex colors, use a badge instead: see Apply Badge Color-Coding.

Troubleshooting

The Field Name toggle is on but the input stays a text box

Dynamic Components versions earlier than 1.54.0 showed a plain text box instead of the field list for every setting under Cell Attributes. Update the package to the latest version and reopen the column.

A class has no effect

Check the spelling, including the underscore (slds-theme_success, not slds-theme-success). A value that is not an SLDS class, such as a hex code, is ignored.

Last updated

Was this helpful?