Server Evaluation of Expressions
Summary
- By default, Expressions are evaluated automatically by AdapTable on the Client
- However sometimes you might wish to perform the evaluation yourself on the server
- AdapTable facilitates this for you by:
- allowing you to choose which Modules (or Expressions) will evaluate on the Server or Client
- firing Events to give you oversight of what needs evaluation
- providing you with the AST that is used by AdapTableQL when managing Expressions
Expression evaluation by AdapTable is generally abstracted away.
End users create Expressions at run-time - either in the UI using Wizards or the Expression Editor - or provide them at design-time in Initial Adaptable State, and everything "just works".
But some developers have a more complicated 2-step use case:
- run-time users will build Expressions
- but the developer team will perform the actual evaluation themselves on their Server
Caution
- This should not be confused with using the Server-Side Row Model which forces server evaluation
- It should also not be confused with Evaluating Expressions via the API which still evaluates using AdapTableQL
This page provides some tips and tricks to help achieve this.
Specifying Externally Evaluated Modules
The first, key, step is to tell AdapTable which Modules (or Expressions) should be evaluated externally.
Note
Four Modules can be evaluated externally: Alerts, Calculated Columns, Column Filters and Grid Filter
This is done via the evaluateAdaptableQLExternally property in Expression Options.
Hint
- This allows you to control when Server evaluation will take place
- e.g. you can evaluate the Grid Filter remotely but let AdapTable manage Calculated Columns and Column Filters
It is in the form of a function which receives context about the Expression / Module and returns a boolean.
Caution
- This is only required when using AG Grid's Client-Side Row Model
- If using the Server-Side Row Model then all filtering (and sorting) is automatically ignored on the client
evaluateAdaptableQLExternally
Default: undefined(context: EvaluateExpressionExternallyContext) => booleanTurning off Automatic Validation
By default, AdapTableQL will validate Expressions automatically as they are being written.
If you are evaluating the Grid Filter on your server you might wish to set performExpressionValidation in Expression Options to false to avoid false positives.
performExpressionValidation
Default: trueBooleanReducing Expression Complexity
Expressions are very rich and powerful, and potentially extremely complex.
When running on the Client that complexity is not problematic as AdapTable takes care of all evaluations.
However if evaluating the Grid Filter (or Calculated Columns) on the server it means a lot of work is required.
AdapTable helps you by allowing you to reduce the compexity of the Expressions in 2 ways:
- Limiting which functions are available in Expressions
- Limiting which columns can be included in Expressions or can be filtered
Find Out More
See Reducing Expression Complexity for more information
AdapTable Events
As noted above, AdapTable will not evaluate any Modules for which the evaluateAdaptableQLExternally function returns true.
Instead developers should subscribe to Adaptable Events designed for this purpose.
Note
This allows developers to perform their own external evaluation as required
The results of the external evaluation will then need to be returned to AdapTable and displayed accordingly.
Hint
- There are many methods in Grid API which can be used to supply data to AdapTable
- The most commonly used is
loadGridData(see Managing Grid Data for more information)
AdapTable will automatically populate AG Grid with any data with which it is provided.
It will also take care or re-applying all column sorts and column formats as required.
The 3 most relevant Adaptable Events are:
Grid Filter Applied
The Grid Filter Applied Event is published any time a Grid Filter runs in AdapTable.
It contains details of the Grid Filter's Expression and the AST used by AdapTableQL to evaluate it.
Column Filter Applied
The Column Filter Applied Event is published each time Column Filters are applied.
Hint
- If evaluating Column Filters externally, you can run them all in one batch if preferred
- To do this set
manuallyApplyColumnFilterin Column Filter Options to true (see Manually Applying Column Filter)
Calculated Column Changed
The Calculated Column Changed Event fires whenever anything changes in Calculated Column State, i.e. if a Calculated Column has been added, edited or deleted.
Using the AST
AdapTable will make the AST it uses when evaulating an Expression available where necessary.
This is available in the Info property provided by the related Adaptable Event:
| Event | Info Class | AST Property |
|---|---|---|
| Grid Filter Applied | GridFilterAppliedInfo | gridFilterExpressionAST |
| Column Filter Applied | ColumnFilterAppliedInfo | columnFilterExpressionASTs |
| Calculated Column Changed | CalculatedColumnChangedInfo | calculatedColumnExpressionAST |
Note
The Column Filter Applied event provides one AST per applied Column Filter
Hint
Any Expression's AST can be retrieved via the getASTForExpression function in the Expression API
- This example demonstrates Server Evaluation using Filters
- In the demo we listen to the Column Filter Applied Event to get the latest applied Filters in the Grid
- We then call our mock Server which translates the Expression into SQL - the rough and ready code we used is here - which runs the associated SQL Query
- The server then returns the new data to AdapTable, which in turn populates AG Grid with it (using Grid API methods)
Expand to see how Filters are evaluated externally
- Run a Column Filter in the Filter Bar and see how the Grid updates
- Note how we output the SQL to System Status Toolbar
JSON Translation
All Column Filter and Grid Filter objects (plus Alerts and Calculated Columns) in Adaptable State are JSON.
Caution
This means that in order to perform searching and filtering on the server this JSON will need to be 'translated' into something that the particular server can understand.
Obviously each server is different so AdapTable cannot provide an out of the box implemenation, but we do work with a number of partners who have performed this for clients.
We also have a Grid Gurus consultancy service who can advise you in a bespoke manner.