Custom Predicate Definitions

Predicate Definitions provided by devlelopers at Design Time

A custom predicate can be used in multiple functions (e.g. Filter, Conditional Style,Alert etc.) which is determined by the functionScope property.

Custom Predicate Def Object

A Predicate Definition is defined as follows:

PropertyDescription
columnScopeColumns (or DataTypes) where Predicate is active
functionScopeAdaptable Functions where the Predicate can run
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
shortcutsKeyboard shortcuts to initiate predicate - used in Quick Filter bar
toStringString representation of the Predicate
note

The id is the unique identifier for the Predicate - label is used when a more friendly way of identifying the Predicate in the UI is required

warning

The handler function need always to be provided

Custom Predicate Def Handler

The handler is a function that receives a PredicateDefHandlerParams object and returns a boolean:

handler: (params: PredicateDefHandlerParams) => boolean;

The PredicateDefHandlerParams is defined as follows:

PropertyDescription
apiThe Adaptable Api
columnColumn which contains the cell
displayValueDisplay value in cell being evaluated
inputsAny inputs required to perform evaluation
nodeRow node which contains the cell
oldValuePrevious value in cell (e.g. if evaluating an edit)
valueRaw value in cell being evaluated

Custom Predicates Exmaple

// Create a Custom Predicate called 'High Invoice'
// and give it column scope of 'OrderId' column
// and function scope of multiple functions
const adaptableOptions: AdaptableOptions = {
customPredicateDefs: [
{
id: 'high_invoice',
label: 'High Invoice',
columnScope: {
ColumnIds: ['OrderId'],
},
functionScope: ['filter', 'conditionalstyle', 'alert', 'cellvalidation'],
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' },
},
],
},
};