Our Biggest Sale Is Here
Up to 70% Off
Get the Deal

How to color cells and rows by their values in wpDataTables

Say your stock table lists 40 products, and you want to see at a glance which ones run low: stock under 10 in red, under 50 in yellow, and everything else in green. Conditional formatting checks the value of each cell against your rules and colors the cell, the whole row or the column, adds a CSS class or replaces the content. You can set the rules with Tabella AI or in the column settings.

How do I add a formatting rule with Tabella AI?

Open the table, click Ask Tabella AI and describe the condition and the color.

  1. Open the table. Go to wpDataTables → wpDataTables and click the table title.
  2. Ask Tabella AI. Click Ask Tabella AI and type, for example: Color the Stock cells red when the value is less than 10. Add more rules in new messages.
  3. Check and save. Read the reply of Tabella AI and check the preview. Click Save Changes to keep the rule, or Undo table changes to go back.

How do I add a formatting rule in the column settings?

Open the Conditional formatting tab of the column, click Add New Rule and fill in the four parts of the rule.

  1. Open the column settings. Open the table, then click the settings icon in the header of the column to check, for example Stock.
  2. Add a rule. In the Conditional formatting tab, click Add New Rule. A row that starts with If cell value appears.
  3. Set the condition. Choose how to compare, for example <, and enter the value to compare with, for example 10.
  4. Set the formatting. Choose what happens when a cell matches, for example Set cell color, and pick the color.
  5. Save the table. Click Save Changes. To delete a rule, click the trash icon at the end of its row.
The Conditional formatting tab of the Stock column in wpDataTables with three Set cell color rules and the Add New Rule button
Three rules on the Stock column: (1) the Conditional formatting tab, (2) the comparison, (3) the value, (4) the operation, (5) the color, (6) Add New Rule.

Video: adding a conditional formatting rule that colors Done cells green.

For a number column, the comparison list has <, ≤, =, ≥, > and ≠. Text columns also compare with contains and does not contain.

Which formatting can a rule apply?

A rule can change the cell, the row or the column of a matching cell:

Operation What it does
Set cell color / Reset cell color to default Colors the matching cell, or removes a color set by an earlier rule.
Set cell content Shows your HTML instead of the value, for example an icon instead of a status. Sorting and filtering still use the original value.
Set cell CSS class / Remove cell CSS class Adds or removes one or more CSS classes on the matching cell.
Set row color / Reset row color to default Colors the whole row of the matching cell, or removes that color.
Set row CSS class / Remove row CSS class Adds or removes CSS classes on all cells of the row.
Set column color Colors the whole column if at least one cell matches. It overrides all other color rules.
Add column CSS class Adds a CSS class to all cells of the column if at least one cell matches.

With server-side processing, the column operations check only the rows on the current page.

In which order do rules apply?

Rules apply from top to bottom, and a lower rule overrides the ones above it. You can use this to build ranges. For the stock example, add the rules in this order:

  1. Stock less than 50: Set cell color yellow.
  2. Stock less than 10: Set cell color red.
  3. Stock greater than or equal to 50: Set cell color green.

Rule 2 overrides rule 1 for values under 10, so cells between 10 and 49 stay yellow. In the opposite order, rule 1 would color everything under 50 yellow, including the values under 10.

A wpDataTables stock table on the front end, sorted by Stock, with stock from 10 to 49 in yellow and 50 and more in green
The result on the front end: (1) stock from 10 to 49 in yellow, (2) 50 and more in green. No product in this table has less than 10, so no cell is red.

How do I format cells by date, such as today or this week?

In Date and DateTime columns, use a date placeholder as the comparison value. The placeholders are below the date picker: %TODAY%, %LAST_WEEK%, %THIS_WEEK%, %NEXT_WEEK%, %LAST_30_DAYS%, %THIS_MONTH%, %LAST_MONTH% and %NEXT_MONTH%. With equal and %TODAY%, the rule colors the cells with today’s date.

The placeholders for a period, such as %LAST_WEEK% or %THIS_MONTH%, need no comparison: every date in that period matches. Use them to highlight, for example, all tasks due this week.

Every rule takes time to render, so keep the number of rules reasonable on large tables.

What should I remember about conditional formatting?

Ask Tabella AI for a rule, or add rules with Add New Rule in the column’s Conditional formatting tab: a comparison, a value, an operation and a color or class. Lower rules override higher ones, which lets you build ranges, and date placeholders such as %TODAY% or %THIS_WEEK% keep date rules up to date.

Wait, Before You Download!

To get your hands on wpDataTables Lite, please enter your email address below. We’ll send you a direct download link and keep you updated on existing features along with helpful tips and tricks!

By continuing, I accept Privacy Policy and T&C
Mail Box