#AdaptableQL (AQL)
AdaptableQL — the Adaptable Query Language, or AQL — is the expression language Adaptable uses wherever data needs to be derived, filtered or styled. An expression is a plain, human-readable string stored in the Adaptable state:
[salary] > 150000 AND [preferredLanguage] = "TypeScript"
Adaptable evaluates expressions against your rows and keeps the results in sync as the data changes.
#Where AQL is used
| Feature | Where the expression lives |
|---|---|
| Calculated columns | expression in the column definition |
| Grid filter | filters.grid in a table view |
| Column filters | filters.columns in a table view |
| Styled cells | condition.expression |
| Alerts and flashing cells | condition.expression |
| Export reports | condition.expression, to pick the exported rows |
| Named queries | expression, reused elsewhere as QUERY("name") |
Calculated columns and named queries can return any value; filters and conditions must return a boolean.
#Expression kinds
Most expressions are standard expressions: they are evaluated for one row at a time, using the values in that row.
AQL also has expressions that look at other rows — aggregated
(AVG{[salary]}), cumulative (SUM{[salary], CUMULATIVE([id])}),
quantile (QUARTILE{[salary]}) and window (RANK{OVER([salary])})
expressions. The editors for calculated columns, the grid filter and alerts
accept every kind; the other features accept standard expressions only.
See Expressions for the syntax and the full list of functions.
#Referencing columns
Columns are written in square brackets, using the column id — not the name of the data field.
availableColumns: {
pay: { field: 'salary', dataType: 'number' },
},With this definition, expressions reference the column as [pay], not
[salary]. A column reference can point to any column available to the
current view, including hidden columns and other calculated columns.
To read a property of the row that is not a column, use
FIELD("name").
#AQL in calculated columns
A calculated column's value is the result of its expression.
The Salary band column has the expression
[salary] > 150000 ? "HIGH" : [salary] > 100000 ? "MEDIUM" : "LOW".
Click the calculated column button in the dashboard to see and edit it.
#AQL in filters
The grid filter is a boolean expression that every row must satisfy. Column
filters are single-column predicates such as [salary] > 110000 — the column
filter UI reads and writes them.
filters: {
grid: '[preferredLanguage] IN ("TypeScript", "Go", "Rust")',
columns: ['[salary] > 110000'],
},The grid filter keeps TypeScript, Go and Rust developers, and a column filter
on salary keeps salaries over 110,000.
#AQL in conditional styles
Styled cells, alerts and flashing cells use a condition — a boolean
expression evaluated row by row. The rule only applies where it is true:
condition: {
expression: '[salary] > 150000 AND [preferredLanguage] = "TypeScript"',
},Scoped rules can use $SCOPE for "the value of the column being styled", so a
single condition works across several columns — for example $SCOPE > 100000.
#Evaluating expressions from code
adaptableApi.adaptableQLApi exposes the engine to your code:
evaluateExpressionForRow(expression, rowData)andevaluateBooleanExpressionForRow(expression, rowData)— evaluate against a row object. They returnundefined(and log a warning once) when the expression cannot be evaluated.evaluateExpression(expression)— the overall value of an aggregated expression, such asAVG{[salary]}.getExpressionType(expression)—'standard','aggregated','cumulative','quantile'or'window'.getExpressionDataType(expression)— the data type the expression returns, when it can be inferred.validateExpression(expression)/isValidExpression(expression)— check an expression against the available columns and fields.
import { useAdaptableApi } from '@adaptabletools/datagrid-react';
function LogAverageSalary() {
const api = useAdaptableApi();
const onClick = () => {
console.log(api.adaptableQLApi.evaluateExpression('AVG{[salary]}'));
};
return <button onClick={onClick}>Log average salary</button>;
}