Implementing Aggregation Binding

Objective

After completing this lesson, you will be able to implement aggregation binding.

Binding Types

In the previous lesson, you learned about the property binding binding type in the context of the JSON model.

Besides property binding, there are two other binding types in SAPUI5: aggregation binding and element binding.

Watch the video to learn about the three binding types.

Aggregations of a control can only be bound to lists defined in the model, that is, to arrays in a JSON model or an entity set in an OData model.

Aggregation Binding Using Template Controls

As mentioned previously, to bind an aggregation, you create a template or provide a factory function. 

Comparison of JSON data and its display in a table UI, showing customer names, streets, and cities.

This section shows how to work with a template control in an XML view. In the example shown here, the entries from an array are to be displayed via a sap.m.Table UI element (see figure Model Data).

Illustration showing JSON model data mapped to a table structure using template controls, demonstrating binding of customer details like name, street, and city from JSON to table columns.

The columns aggregation is used to define the three columns of the table with their headers (see the figure Data Binding). No data binding is used for this yet.

For the display of the data, a binding to the items aggregation of the sap.m.Table UI element is applied. The items aggregation defines the entries displayed in the table.

The items="{/Customers}" attribute of the <Table> tag is used to pass the elements of the Customers array from the JSON model to the items aggregation of the table. The absolute binding path /Customers is needed for this purpose.

The aggregation binding requires the definition of a template that is cloned for each element of the passed array. For each clone that is created, the binding context is thereby set to the respective array element, so that all bindings of the template are resolved relative to the array element.

The template can be found in the nested items element in the figure Data Binding. It is a sap.m.ColumnListItem control that creates a new row for the table. This row displays customer name, street as well as city from the respective array element.

Note

The binding paths used within the sap.m.ColumnListItem control are all relative, as they are resolved relative to the array element for which the template is cloned.