---json
{
"page_id": "0xj7xu3xdj7mvqmt3rovo"
}
---
====== Expression Generator ======
===== About =====
A ''expression data-supplier'' is a [[data-supplier|column data supplier]] that can generate data created from:
* other columns (known as ''parent columns'')
* by giving an ''expression (or formula)''.
===== Example =====
* [[:howto:generator:expression]]
===== Syntax =====
columns:
- name: column_name
data-supplier:
type: expression
arguments:
# The name of a column used in the expression
column-variable: columnVariableName # becomes in the expression, the variable columnvariablename
# A list of column name used in the expression
column-variables:
- columnVariableName1 # becomes in the expression, the variable columnvariablename1
- columnVariableName2 # becomes in the expression, the variable columnvariablename2
- ......
# The expression
expression: "javascriptExpression"
==== Arguments ====
The [[:docs:conf:parameter|arguments]] of the [[:docs:generator:data-supplier|data supplier node]] are:
^ Name ^ Description ^
| ''column-variable'' | A column name used in the expression as variable |
| ''column-variables'' | A list of column names used in the expression as variables |
| ''expression'' | The [[#expression]] |
===== What are Expressions ?=====
Expressions are Javascript expressions.
Tabulify pass the data as native javascript [[docs:data_type:data_type|data type]] in a variable with the name of the column in lowercase.
You don't need to instantiate the variables, Tabulify do.
Note:
* For [[docs:data_type:date_time|date/timestamp/time data type]], we create a [[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date|Date]] as this is the only temporal data type of javascript.
* For all numbers (Double, Integer, ...) , we create a [[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number|Number]] as this is also the only number data type of javascript.
Example for ''2009/10/01'' and the column name ''date'' or ''DATE'', Tabulify would create the `date` variable like this:
date = new Date("2009","10","01")
And if you want the month, you expression would use [[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth|getMonth]] :
date.getMonth()+1
===== How to hide intermediate columns ?=====
When creating an expression generator, you may want to create columns that should not appear in the data generated.
For this purpose, you can use the ''hidden'' property.
Example:
- name: columnToHide
Hidden: true # The column will not be added to the output.
Description: An hidden column
data-supplier:
type: entity
===== Data Type =====
The below [[docs:data_type:data_type|data type]] are supported:
^ Data Type ^ Java script Equivalent ^
| [[:docs:data_type:integer|Integer]] | [[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number|Number]] |
| [[:docs:data_type:double_real_float|Double/Float]] | [[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number|Number]] |
| [[:docs:data_type:numeric_decimal|Numeric/Decimal]] | [[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number|Number]] |
| [[:docs:data_type:date_time|Date/Timestamp]] | [[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date|Date]] |
| [[..:data_type:character|Varchar/Char]] | [[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String|String]] |