Conditional Styling
Summary
- Optional Rules on Format Column definitions — apply a style or display format only when a cell or row matches
- Most Conditions are change-based (boolean over cell values) but Observable (live history / time) are also supported
- Scoped to specific columns or whole rows
- Conditions use an Expression (AdapTableQL)
Format Columns can be provided with a Rule — which specifies whether or not to render the Format.
This allows users to create very visually striking Grids with a minimum of effort.
Conditions can be applied to both elements of Column Formatting:
Expression
The Rule is a Boolean Expression (it must evaluate to true / false), evaluated by AdapTableQL.
Note
Expressions are very powerful and can contain multiple criteria and AND / OR logic
Conditions are evaluated in Real Time so Format Columns are applied automatically as Grid data updates.
Caution
Format Columns with Conditions are only applied when the cell values satisfy all supplied criteria in the Expression
This example provides 2 conditional Styles:
- A Row Condition (
Scope: All) which highlights the whole Row whenLanguageis 'TypeScript' - A Column Condition (
Scope: a single Column) which coloursWeekly Issue Changegreen and bold when the value is positive
This example provides 2 conditional Display Formats:
- A Column Condition (
Scope: a single Column) which abbreviatesGitHub Stars(e.g.12.3K) when the repo has 1,000 or more stars - A Data Type Condition (
Scope: all number Columns) which displays any negative number in parentheses
Using $SCOPE
Sometimes a Format Column's Column Scope covers more than one column (i.e. it could be a Data Type, or a Column Type, or a list of ColumnIds).
When this happens the Rule should not individually include every Column.
Instead, you should use the $SCOPE AQL Expression Function.
$SCOPE is a stand-in for whichever column in the Scope is being formatted.
Hint
- This allows you to create one rule which covers all columns of a type (including ones not yet created)
- e.g. a green font style for all positive numeric columns (or red and parentheses for negative)
- This example provides 2 Format Columns, both with a Scope of all
numbercolumns:- Positive -
IS_POSITIVE($SCOPE)paints the cell green and bold - Negative -
IS_NEGATIVE($SCOPE)paints the cell red and bold
- Positive -
- The same rules apply to every numeric column - there is no need to list
ColumnIdsor write a separate Expression per column.
- Look at
Weekly Issue Changefor both colours (it has positive and negative values) - Click the Add "Total GitHub" Column button to add a Calculated Column - this turns green automatically, because the
$SCOPERule also coversnumbercolumns created later
Observable Conditions
In addition to standard change-based Conditions, AdapTable also supports Observable Condition
Note
- These are evaluated using a live Observable Expression (history / time) and the cell is formatted if it returns true
- e.g. to format a cell where price is unchanged in 5 seconds use:
NO_CHANGES{[price], WITHIN(5s)}
FAQ
Do I have to provide a Condition? No, Formats can be applied across all cells in all columns in Scope without any Condition being supplied (choose No Condition in the Wizard).
What is the difference between Standard and Observable Conditions? Standard is a boolean over current cell / row values. Observable reads change history or time (e.g. stale cells, busy windows). See Observable Format Column Conditions.