> For the complete documentation index, see [llms.txt](https://docs.avonnicomponents.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/data-table/apply-conditional-cell-styling.md).

# 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.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2Fei2oTgEAgZcq8OkEmOlD%2Fdata-table-tutorial-apply-conditional-cell-styling-result.png?alt=media" alt="Data Table of opportunities where each Stage cell has a background color matching its stage, and amounts are bold."><figcaption><p>Stage cells take their SLDS classes from the Stage Style formula field.</p></figcaption></figure>

## Before you start

* A [Data Table](https://docs.avonnicomponents.com/dynamic-components/components/data-table.md) on Opportunity with a [Query](https://docs.avonnicomponents.com/dynamic-components/component-builder/data-sources/query.md) data source, showing at least the **Opportunity Name**, **Stage** and **Amount** columns.
* Permission to create a formula field on Opportunity (Customize Application).

## Steps

{% stepper %}
{% step %}

### 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](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/data-table/apply-badge-color-coding.md) and [Add Status Indicators](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/data-table/add-status-indicators.md).

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:

```
CASE(StageName,
  "Prospecting", "slds-theme_shade",
  "Qualification", "slds-theme_shade",
  "Needs Analysis", "slds-theme_info",
  "Value Proposition", "slds-theme_info",
  "Id. Decision Makers", "slds-theme_info",
  "Perception Analysis", "slds-theme_info",
  "Proposal/Price Quote", "slds-theme_warning",
  "Negotiation/Review", "slds-theme_warning",
  "Closed Won", "slds-theme_success",
  "Closed Lost", "slds-theme_error",
  ""
)
```

Any other stage returns an empty value and keeps the default cell style.
{% endstep %}

{% step %}

### 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**.
   {% endstep %}

{% step %}

### 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.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FbhGlHt5JHuPjdbsNLovR%2Fdata-table-tutorial-apply-conditional-cell-styling-panel.png?alt=media" alt="Cell Attributes of the Stage column with SLDS Cell Class bound to the Stage Style field." width="320"><figcaption><p>SLDS Cell Class bound to the formula field with the Field Name toggle.</p></figcaption></figure>
{% endstep %}

{% step %}

### 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.
{% endstep %}
{% endstepper %}

## 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                                           |

{% hint style="info" %}
**SLDS Cell Class** takes class names, not colors. To use your own hex colors, use a badge instead: see [Apply Badge Color-Coding](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/data-table/apply-badge-color-coding.md).
{% endhint %}

## Troubleshooting

<details>

<summary>The Field Name toggle is on but the input stays a text box</summary>

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.

</details>

<details>

<summary>A class has no effect</summary>

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.

</details>

## Related tutorials

* [Apply Badge Color-Coding](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/data-table/apply-badge-color-coding.md): color the value itself, with your own hex codes.
* [Add Status Indicators](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/data-table/add-status-indicators.md): a compact dot when the table is narrow.
* [Configuring Data Grouping](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/data-table/configuring-data-grouping.md): group rows by stage so the tinted cells line up.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.avonnicomponents.com/dynamic-components/tutorials/components/data-table/apply-conditional-cell-styling.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
