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:
Property | Description |
---|---|
columnScope | Columns (or DataTypes) where Predicate is active |
functionScope | Adaptable Functions where the Predicate can run |
handler | Actual boolean function invoked when evaluating the Predicate |
icon | Icon to show (primarily used in Filter dropdown) |
id | Unique Id for the object |
inputs | Inputs the Predicate can take |
label | Name of the Predicate |
shortcuts | Keyboard shortcuts to initiate predicate - used in Quick Filter bar |
toString | String 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:
Property | Description |
---|---|
api | The Adaptable Api |
column | Column which contains the cell |
displayValue | Display value in cell being evaluated |
inputs | Any inputs required to perform evaluation |
node | Row node which contains the cell |
oldValue | Previous value in cell (e.g. if evaluating an edit) |
value | Raw 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' },
},
],
},
};