Show TOC

Calculated Fields for Data BindingLocate this document in the navigation structure

Calculated fields enable the binding of multiple properties in different models to a single property of a control.

The value property of a text field, for example, may be bound to a property firstName and a property lastName in a model. The application can access these values in a formatter function and can decide how they should be processed or combined together. If no formatter function is specified, the values are joined together by default. You can use the useRawValues property to specify if the parameter values in the formatter function are formatted according to the type of the property or not.

The multiple property bindings are stored in a CompositeBinding and can be accessed by calling the getBindings function. You can access the composite binding, for example, by using the getBinding('value') function of the control. The composite binding has no path, model, context, and type because it contains multiple property bindings containing the necessary information. A composite binding may, for example, store two property bindings which belong to different models and have different types.

If you have specified a formatter function, it is also available in the composite binding.

Note Currently, calculated fields work only from model to view, read only, and the values can be accessed via a formatter function.

There are several options to create multiple bindings for a control. The syntax is very similar to the normal single binding declaration.

Each binding is created by the specified parts and assigned information. A part must contain the path to the property in the model and may contain additional information for the binding, for example a type. If multiple parts exist, the binding mode is automatically set to one-way binding.

Constructor Declaration
  1. Use binding objects to add additional parameters, for example the type:
    oTxt = new sap.ui.commons.TextField({
        value: {
            parts: [
                    {path: "/firstName", type: new sap.ui.model.type.String()},
                    {path: "/lastName"},
                    {path: "myModel2>/amount", type: new sap.ui.model.type.Float()} // path to property in another model
                   ]
              }
    }); 
  2. Use strings which only take the path:
    oTxt = new sap.ui.commons.TextField({
        value: {
            parts: [
                    "/firstName",
                    "/lastName",
                    "myModel2>/fraud" // path to property in another model
                   ]
             }
    }); 
Bind Property Declaration
  1. Use binding objects to add additional parameters, for example the type:
    oTxt.bindValue({
        parts: [
                {path: "/firstName", type: new sap.ui.model.type.String()},
                {path: "/lastName"}
               ]
    }); 
  2. Use strings which only take the path:
    oTxt.bindValue({
        parts: [
                "/firstName",
                "/lastName"
               ]
    }); 

These samples also work with a relative binding path, when you use them as a template in an aggregation binding.