SMART datagrid v.1 > Classes > DerivedField

Back  Forward

DataLudi.DerivedField.expression  property

Expression which returns the value to be saved in field. 

You can directly use the name of common fields as variable in expression, but should not refer other derived field. You can also return the value by callback property instead of this expression. 

You can use the variables listed in the table below in expression besides common field names. 

Defaults to null.

Getter
function expression(): String
Setter
function setExpression(value: String)
Table-1  DereivedField.expression variables
VariableExplanation
'row'The index of data row
'values'Get the value by field name or field index of common fields.
Code -1
    var fields = [];
    var calcedFields = [
        {
            fieldName: "amount",
            dataType: "number",
            expression: "unit_price * quantity"
        },
        ...
    ];
    ds.setFields(fields, calcedFields);

When the field name starts with number, since expression parser will read it as number value, you should use "values" variable. 

Code -2
    var fields = [];
    var calcedFields = [
        {
            expression: "values['01_unit'] * values['02_unit']"
        },
        ...
    ];

You should not refer other derived field in expression. 

See Also
callback
DataSet.setFields
Expression Overview
Examples
Derived Fields
Row Summary