Predicate
Version 7 of AdapTable introduced a new concept called a Predicate which is used in many functions.
Essentially a Predicate is a type that returns a boolean value.
Predicate Handler
A predicate includes a handler
function. This will run each time the predicate is required, and evaluate the contents of the given cell (or alert or data change) against the predicate type and return either true or false.
For instance the 'Blanks' predicate will check all column types to see if the value is empty, while the 'Positive' predicate will check the value of a number cell to see if its greater than 0.
Predicate Inputs
Some Predicates require an additional input value in order to perform the evaluation.
For instance 'GreaterThan' compares the input value against base value and returns true if the latter is larger.
The input is passed in as an array. The reason is that while most inputs are a single value, some require 2 inputs (e.g. between) while the 'In' Predicates (also known as 'Values') can take an array of unlimited length.
Column Scope
Each Predicate has a ColumnScope property of type Scope which defines where it can be applied.
note
For System Predicates the Scope is always of type 'DataType' but for Custom Predicates (see below) the Scope can be limited to particular ColumnId(s)
Function Scope
A Predicate also has a FunctionScope which defines in which Adaptable Functions the Predicate is available.
The value will be one, some, or all of the following functions:
System Predicates
AdapTable ships with a number of Predicates which are available to use across the Grid.
Most of these are available in all functions that use Predicates but there are one or two exceptions. See the list below for more details.
Multiple Variations
warning
Because we wish to ensure that each Predicate is used by one DataType only - we sometimes have more than one predicate for the same type of operation but with a different name.
For example AdapTable offer an 'equality' type valuation via 3 different predicates:
- Number: Equals
- String: Is
- Date: On
Likewse there is a Numeric 'GreaterThan' and a Date 'After'
Values Predicate
Most Predicates are relatively straightforward.
They take either no inputs (e.g. Blanks) or just 1 input (e.g. GreaterThan).
The one exception is the Values Predicate which works like the SQL 'IN' operator.
note
The Values Predicate is only available in Column Filter
It receives an array of values and returns true for each row where the Column contains one of the values.
tip
When selected, AdapTable provides a popup form with a checkbox list of all distinct Column values
System Predicate List
The Predicates shipped by AdapTable are:
Predicate | Column Data Type | Inputs | Where Used |
---|---|---|---|
Values | All | 0 | Column Filter |
Blanks | All | 0 | Column Filter, Alert, Validation, Conditional Style |
NonBlanks | All | 0 | Column Filter, Alert, Validation, Conditional Style |
Equals | Number | 1 | Column Filter, Alert, Validation, Conditional Style |
NotEquals | Number | 1 | Column Filter, Alert, Validation, Conditional Style |
GreaterThan | Number | 1 | Column Filter, Alert, Validation, Conditional Style |
LessThan | Number | 1 | Column Filter, Alert, Validation, Conditional Style |
Positive | Number | 0 | Column Filter, Alert, Validation, Conditional Style |
Negative | Number | 0 | Column Filter, Alert, Validation, Conditional Style |
Zero | Number | 0 | Column Filter, Alert, Validation, Conditional Style |
Between | Number | 2 | Column Filter, Alert, Validation, Conditional Style |
NotBetween | Number | 2 | Column Filter, Alert, Validation, Conditional Style |
PercentChange | Number | 0 | Alert, Validation |
IsNumeric | Number | 0 | Validation |
Is | String | 1 | Column Filter, Alert, Validation, Conditional Style |
IsNot | String | 1 | Column Filter, Alert, Validation, Conditional Style |
Contains | String | 1 | Column Filter, Alert, Validation, Conditional Style |
NotContains | String | 1 | Column Filter, Alert, Validation, Conditional Style |
StartsWith | String | 1 | Column Filter, Alert, Validation, Conditional Style |
EndsWith | String | 1 | Column Filter, Alert, Validation, Conditional Style |
Regex | String | 1 | Column Filter, Alert, Validation, Conditional Style |
Today | Date | 0 | Column Filter, Alert, Validation, Conditional Style |
Yesterday | Date | 0 | Column Filter, Alert, Validation, Conditional Style |
Tomorrow | Date | 0 | Column Filter, Alert, Validation, Conditional Style |
ThisWeek | Date | 0 | Column Filter, Alert, Validation, Conditional Style |
ThisMonth | Date | 0 | Column Filter, Alert, Validation, Conditional Style |
ThisQuarter | Date | 0 | Column Filter, Alert, Validation, Conditional Style |
ThisYear | Date | 0 | Column Filter, Alert, Validation, Conditional Style |
InPast | Date | 0 | Column Filter, Alert, Validation, Conditional Style |
InFuture | Date | 0 | Column Filter, Alert, Validation, Conditional Style |
Before | Date | 1 | Column Filter, Alert, Validation, Conditional Style |
After | Date | 1 | Column Filter, Alert, Validation, Conditional Style |
On | Date | 1 | Column Filter, Alert, Validation, Conditional Style |
NotOn | Date | 1 | Column Filter, Alert, Validation, Conditional Style |
NextWorkDay | Date | 0 | Column Filter, Alert, Validation, Conditional Style |
LastWorkDay | Date | 0 | Column Filter, Alert, Validation, Conditional Style |
True | Boolean | 0 | Column Filter, Alert, Validation, Conditional Style |
Any | All | 0 | Alert, Validation |
ExistingValuesOnly | All | 0 | Alert, Validation |
NoDuplicateValues | All | 0 | Alert, Validation |
PrimaryKeyDuplicate | PK Column | 0 | Alert, Validation |
Using Predicates
The AdaptablePredicate object has just 2 properties:
Property | Description |
---|---|
Inputs | Optional inputs - needed to evaluate some Predicates (e.g. 'GreaterThan') |
PredicateId | Id of Predicate (e.g. 'Equals', 'GreaterThan') |
note
The Inputs
property is required when the Predicate needs additional information for evaluation.
Referencing a Predicate
It is straightforward to reference a Predicate in Predefined Config:
Custom Predicates
Developers are encouraged to create their own Predicates at DesignTime via the Custom Predicate Defs section of Adaptable Options.
Demos
Visit the AdapTable Demo Site to see a number of demos that use Predicates