Derived Field is a field which stores the result calculated by the values of common fields. When set the fields in the data set through DataSet.setFields, it will be specified after separating from common fields and always located after them.
var fields = [...];
var calcedFields = [...];
ds.setFields(fields, calcedFields);
You can specify the value of Derived Field through expression or callback function. In the example above, "Sum" field has been specified through expression, and "Sum2" field has been specified through callback function. Differently from Calculated Column, since the values will be saved in the data set in Derived Field actually, you can display the total value in the footer as in the example.
var calcedFields = [{
fieldName: "amount",
expression: "unit_price * quantity" // The name of another fields can be used as a variable.
}, {
fieldName: "amount2",
callback: function (ds, fld, row, values) {
return values[8] * values[9];
}
}];
dataset.setFields(fields, calcedFields);
In expression, you can directly use the name of another field as a variable as in the example, but you cannot reference another Derived Field. In addition, since PARSER will recognize it as a numeric value when the field name starts with a number, you should use "values" operator as below.
var calcedFields = [{
fieldName: "amount",
expression: "values['01_unit'] * values['02_unit']"
},
...
]