Album Table Feature

SAPUI5 Different Table Bindings

One of the commonly asked question on SAPUI5 is regarding different table bindings. Today let’s discuss, how can we really bind data to a table in SAPUI5 in 3 different ways.

The Problem

Often times developers always encounter how to display multiple data at once to a table. In SAPUI5 this can be very tricky especially if the table representation is more complex than the usual.
Common problems arise from wrong binding path, different column display, up to dynamically generated rows based on logic.

The Solution

So how can we represent data on a SAPUI5 table? What are the options available to us?
Before we begin, let’s say we have the table below. The table displays a list of albums with an image.

You can also refer to this tutorial on how to make SAPUI5 projects with best practices.

Albums Table
Albums Table

This table contains a modified copy of albums API from JSON Placeholder. Below is a sample data of the table:

Using the table above, let’s use the 3 different ways to data bind tables in SAPUI5.

Row or Item Binding

The most common way to bind data to a table is to use bindItems or items property on XML view.

Let’s breakdown the XML view above.

In our table control, we set up the binding path to the target aggregation. Here items is a aggregation property, which accepts a collection of data. The value {album>/rows} pertains to a segment is our albums JSON Model, see highlighted image below.

SAPUI5 will interpret the binding path {album>/rows} and read the the JSON Model to fetch the equivalent data on the specific node, in this example rows segment will return all the albums collection. This binding will produce the table below:

Albums Table
Albums Table

Column Binding

We now proceed to column data binding. Like row or items binding, the column binding refers to a collection to render multiple headers of a SAPUI5 table.

The highlighted lines above shows that the columns property is bound to a collection {albums>/columns}. Looking at our JSON model, see below, we can see that the columns tag is bound to the values of each column in the JSON model.

Each Column contains an inner control, for example, Text which is bound to {albums>label}. Notice the absence of “/”, this is due to fact that during column binding, all path will act as relative path.

The binding will result to the table below:

Album Table Column Binding
Album Table Column Binding

Factory Binding

Other than items and columns binding, another way to generate the contents of the table is via factory method. The factory method is like any other method, except it will be called for each entry on the aggregation.
So going back to our JSON model, columns contains 3 entries, Album ID, Album Title, and Cover, the factory will be executed 3 times to build the SAPUI5 control.

Notice in the above source code, we don’t have an items tag to render the table rows. Instead we have a factory attribute on items property. This method can be found on our controller.

In the code above, we check if the property binding contains a status with a value of active, this will result to change of returned control to customize the row item of the table. The table below shows that other rows render differently according to status.

Album Table Factory Method
Album Table Factory Method


In conclusion, we can utilize these different binding styles on a table to our need. This enables us to dynamically create complex layout without too much code and make of use of data binding with ease.
But do take note not to overuse the factory method and prioritize make use of items and columns binding, as this will result to additional processing time.

All the source code above can be found in this repository.

If you like this post, let me know in the comment section. Don’t forget to like and subscribe!

Leave a Reply

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.