Adaptable Predicate

A Predicate is a type that returns a boolean value and is used in 3 AdapTable Modules:

note

Column Filters only supports Predicates while the others allow objects to use either Predicates or Queries depending on the complexity required

Using Predicates

The AdaptablePredicate object has just 2 properties:

PropertyDescription
InputsOptional inputs - needed to evaluate some Predicates (e.g. 'GreaterThan')
PredicateIdId 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 create a Predicate in Predefined Config:

predefinedConfig: {
Filter: {
ColumnFilters: [
{
// Using no inputs
ColumnId: 'Price',
Predicate: {
PredicateId: 'Positive',
},
},
{
// Using 1 input
ColumnId: 'OrderId',
Predicate: {
PredicateId: 'GreaterThan',
Inputs: [15],
},
},
{
// Using 2 inputs
ColumnId: 'Age',
Predicate: {
PredicateId: 'Between',
Inputs: [18, 65],
},
},
{
// Providing Values
ColumnId: 'Currency',
Predicate: {
PredicateId: 'Values',
Inputs: ['GBP', 'USD'],
},
],
},
ConditionalStyle: {
ConditionalStyles: [
{
Scope: {
DataTypes: ['Number'],
},
Style: {
ForeColor: 'Green',
},
Rule: {
Predicate: {
PredicateId: 'Positive',
},
},
},
],
},
};

Predicate Definition

The Predicate Definition defines what the Custom Predicate does and where it can be used:

PropertyDescription
columnScopeColumns (or DataTypes) where Predicate is active
handlerActual boolean function invoked when evaluating the Predicate
iconIcon to show (primarily used in Filter dropdown)
idUnique Id for the object
inputsInputs the Predicate can take
labelName of the Predicate
moduleScopeAdaptable Modules where Predicate can run
onlyQuickFilterWether to display this predicate only in QuickFilter (and NOT in Column Filter)
shortcutsKeyboard shortcuts to initiate predicate - used in Quick Filter bar
toStringString representation of the Predicate

Of this properties there are some worthy of note:

Id

The name given to the Predicate and how it is referenced in the AdapTable UI

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.

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)

Module Scope

A Predicate also has a ModuleScope which defines in which Modules the Predicate is available.

note

The value will be one, some, or all of Filter, Alert and ConditionalStyle

Example

This definition of the 'GreaterThan' Predicate shows all these properties.

It has a Column Scope of 'Number' and wide Function Scope, and receives a single input (of type 'number')

id: 'GreaterThan',
label: 'Greater Than',
icon: { path: 'greater-than' },
columnScope: { DataTypes: ['Number'] },
moduleScope: ['filter', 'alert', 'conditionalstyle'],
inputs: [{ type: 'number' }],
handler: ({ value, inputs }) => Number(value) > Number(inputs[0]),
toString: ({ inputs }) => `> ${inputs[0]}`,
shortcuts: ['>'],

System Predicates

AdapTable ships with a number of Predicates which are available to use across the product.

Most of these are available in all Modules 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 in 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 (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:

PredicateColumn Data TypeInputsColumn FilterAlertConditional Style
ValuesAll0โœ…
BlanksAll0โœ…โœ…โœ…
NonBlanksAll0โœ…โœ…โœ…
EqualsNumber1โœ…โœ…โœ…
NotEqualsNumber1โœ…โœ…โœ…
GreaterThanNumber1โœ…โœ…โœ…
LessThanNumber1โœ…โœ…โœ…
PositiveNumber0โœ…โœ…โœ…
NegativeNumber0โœ…โœ…โœ…
ZeroNumber0โœ…โœ…โœ…
BetweenNumber2โœ…โœ…โœ…
NotBetweenNumber2โœ…โœ…โœ…
PercentChangeNumber0โœ…
IsNumericNumber0โœ…
IsString1โœ…โœ…โœ…
IsNotString1โœ…โœ…โœ…
ContainsString1โœ…โœ…โœ…
NotContainsString1โœ…โœ…โœ…
StartsWithString1โœ…โœ…โœ…
EndsWithString1โœ…โœ…โœ…
RegexString1โœ…โœ…โœ…
TodayDate0โœ…โœ…โœ…
YesterdayDate0โœ…โœ…โœ…
TomorrowDate0โœ…โœ…โœ…
ThisWeekDate0โœ…โœ…โœ…
ThisMonthDate0โœ…โœ…โœ…
ThisQuarterDate0โœ…โœ…โœ…
ThisYearDate0โœ…โœ…โœ…
InPastDate0โœ…โœ…โœ…
InFutureDate0โœ…โœ…โœ…
BeforeDate1โœ…โœ…โœ…
AfterDate1โœ…โœ…โœ…
OnDate1โœ…โœ…โœ…
NotOnDate1โœ…โœ…โœ…
NextWorkDayDate0โœ…โœ…โœ…
LastWorkDayDate0โœ…โœ…โœ…
RangeDate2โœ…โœ…โœ…
TrueBoolean0โœ…โœ…โœ…
AnyAll0โœ…
ExistingValuesOnlyAll0โœ…
NoDuplicateValuesAll0โœ…
PrimaryKeyDuplicatePK Column0โœ…

Custom Predicates

Developers are encouraged to create their own Predicates at DesignTime via the Custom Predicate Defs section of Adaptable Options.

Once created, they can be used in exactly the same way as System Predicates:

// Create a Custom Predicate called 'High Invoice'
// and give it column scope of 'OrderId' column
// and module scope of multiple Modules
const adaptableOptions: AdaptableOptions = {
customPredicateDefs: [
{
id: 'high_invoice',
label: 'High Invoice',
columnScope: {
ColumnIds: ['OrderId'],
},
moduleScope: ['filter', 'conditionalstyle', 'alert'],
handler(params: PredicateDefHandlerParams) {
const invoiced: number = params.node.data.InvoicedCost;
const itemCount: number = params.node.data.ItemCount;
return invoiced > 100 && itemCount > 10 ? true : false;
},
}
],
// Create a Column Filter in Predefined Config
// and use the Custom Predicate defined above
predefinedConfig: {
Filter: {
ColumnFilters: [
{
ColumnId: 'OrderId',
Predicate: { PredicateId: 'high_invoice' },
},
],
},
};

Demos

Visit the AdapTable Demo Site to see a number of demos that use Predicates