AdapTable Predicates
Summary
- An Adaptable Predicate is a boolean function (system or custom) which evaluates to a true / false value
- Designed to be lightweight and easy to use - both in the Adaptable UI and in Initial Adaptable State
- Used primarily in Column Filters but also in Alerts, Badges, Flashing Cells and Conditional Styles
AdapTable Predicates are used for creating, and evaluating, boolean Rules.
Note
- AdapTable also provides Expressions which are designed for more complex use cases
- They are an entirely different way to query data in AdapTable and are evaluated using AdapTableQL
Caution
- You can use either Predicates or Expressions for any given use case, but they cannot be mixed together
- e.g. you cannot include a Custom Predicate in an Expression, or reference an Expression Function in a Predicate
Predicates Overview
A Predicate is a function which always returns a boolean result (e.g. Positive, Today).
Some Predicates receive an input argument, e.g. Contains (number), After (date), Between (2 numbers)
Predicates are usually evaluated against one or more Columns or DataTypes
AdapTable makes creating Predicates in the UI easy by providing context sensitive dropdows that contain only values relevant to the current use case.
Hint
- Predicates required for Initial Adaptable State can be entirely handwritten if that is the preference
- Alternatively, they can be first created in the UI and then the contents copied over into the Initial State file
Predicate Types
There are 2 types of Predicates:
-
System Predicates - shipped by AdapTable and designed to cover most use cases
-
Custom Predicates - defined by developers in Adaptable Options - used to meet precise user requirements
Module Scope
Predicates can be used in 5 Modules in AdapTable:
Note
We have also noted where Expressions can be used as an alternative to Predicates
| Module | No.of Predicates Allowed | Module also uses Expressions |
|---|---|---|
| Alerts | Multiple | ✅ |
| Column Filters | One | ❌ |
| Format Columns | Multiple | ✅ |
| Flashing Cells | Multiple | ✅ |
| Badge Styled Columns | Multiple | ❌ |
DataType Scope
Each System Predicate is designed to be used by one Column DataType only e.g. number, date or text.
Note
There are 4 exceptions: Blanks, NonBlanks, In & NotIn which can be applied to every DataType
Similar Behaviour
For the majority of Predicates the single Data Type Scope rule is not a problem
This is because they are only relevant to a single DataType (e.g. ThisWeek has to be a Date).
However, a few Predicate behaviours (e.g. Equals) can be suitable for more than one DataType.
When this happens a differently and appropriately named Predicate is provided for each DataType.
Here are some examples of similar behaviours with different Predicates for each Data Type:
| Numeric | Date | String |
|---|---|---|
Equals | On | Is |
GreaterThan | After | |
LessThan | Before | |
Between | Range |
Find Out More
- The System Predicates List provides a full list of System Predicates shipped by AdapTable
- It also includes details of both Module and Column Data Type Scope
Using Predicates
Predicates are designed to be easy to use both at run-time and design-time.
The AdaptablePredicate object contains just 2 properties:
| Property | Description |
|---|---|
| Inputs | Optional Inputs that might be needed for evaluation |
| PredicateId | Id of Predicate (e.g. Equals, GreaterThan) |
Inputs are used when the Predicate requires extra information for its evaluation; they can receive:
- 0 inputs (e.g.
Blanks) - 1 input (e.g.
GreaterThan) - 2 inputs (e.g.
Between) - array of inputs (only used in
In&NotInin Column Filter Predicates - similar to SQL 'IN')
Note
AdapTable's evaluation for In Predicate returns true if the Column contains any of the values
Creating Predicates at RunTime
Predicates are straightforward to use in the AdapTable UI.
AdapTable will provide a list of available Predicates automatically generated according to context.
For example, if the Scope is a number and the Module is Alert, then only numeric Predicates supported by Alerts will be displayed.
Hint
AdapTable ensures Custom Predicates are only selectable where their Column or DataType scope allows
Once the Predicate has been selected an input control (or controls) will appear if the Predicate requires inputs.
The control displayed will vary based on the input DataType (e.g. a Date Picker if a date is required)
Defining Predicates in Initial State
It is straightforward to supply a Predicate in Initial Adaptable State.
The PredicateId is always required and Inputs should be provided if required by the Predicate for evaluation:
const initialState: InitialState = {
Layout: {
CurrentLayout: 'Table Layout',
Layouts: [
{
Name: 'Table Layout',
TableColumns: [
'OrderId',
'Price',
'Age',
'Currency',
'TradeDate',
],
ColumnFilters: [
{
// Using no inputs
ColumnId: 'Price',
Predicates: [{ PredicateId: 'Positive' }],
},
{
// Using 1 input
ColumnId: 'OrderId',
Predicates: [{ PredicateId: 'GreaterThan', Inputs: [15] }],
},
{
// Using 2 inputs
ColumnId: 'Age',
Predicates: [{ PredicateId: 'Between', Inputs: [18, 65] }],
},
{
// Providing In Predicate as array
ColumnId: 'Currency',
Predicates: [{ PredicateId: 'In', Inputs: ['GBP', 'EUR', 'USD'] }],
},
{
// Using a Custom Predicate
ColumnId: 'TradeDate',
Predicates: [{ PredicateId: 'ThisBusinessYear'] }],
},
],
},
],
},
FormatColumn: {
FormatColumns: [
{
Name: 'positive-green',
Scope: { DataTypes: ['number'] },
Style: { ForeColor: 'Green'},
Rule: {
Predicates: [{ PredicateId: 'Positive' } ]
},
},
],
}
};Accessing Predicates programmatically
The Predicate API section of Adaptable API contains a number of functions providing access to Predicates.