0
votes

I try to display a list of objects from an OData V4 service in SAP UI5. I would like to use a property from a JSON Model to set the binding path for the list items.

I thought I can just set the path in the items aggregation of the table:

<Table
  items="{
    path: '{appView>/dataPath}',
    parameters: {
      $count: true,
      $$updateGroupId: 'peopleGroup'
    }
  }">...</Table>

and of course define and set the model:

var oViewModel = new JSONModel({
  dataPath: "/People"
});

this.getView().setModel(oViewModel, "appView");

For some reason the data is not loaded. There is not even items binded to the table:

oTable.getBinding("items");  // undefined

The JSON Model is defined in the init method of the controller.

Anybody has an idea why this is not working?

3
would suggest binding oData directly on the Table. You are creating an empty new JSONModel anywayMedera
The reason why I want to do this is that this view is used for two different entities. So depending on the source I want to bind different paths to this table.Marvin K
can you add the information where you retrieve the oData call or where you get any data?Medera
The OData Model is created as the default model in the manifest.json. Therefore the binding '/People' fetches the data from the OData Service.Marvin K

3 Answers

1
votes

As per my understanding you want to bind path dynamically.in such case you can write template in xml without any path then in controller you have write bind path XML View:

<Table id="tblData" items="{}"> <items> **template code ** </items> </Table>

Controller:

var oTable = this.getView().byId("tblData"),
    sPath = this.getModel("appView").getProperty("/dataPath"),
    oBinding = oTable.bindItems({path: sPath});

for filters:

oBinding.filter(aFilters);
0
votes
items: "{
  path: '{appView>/dataPath}',

Anybody has an idea why this is not working?

Binding definitions apply only for ManagedObject's properties and aggregations. As path is just a plain object property, trying to bind anything there will be ignored.

-1
votes

Since you want to bind the Table to the result of the {appView>/dataPath} binding, I think you need to use Expression Binding to solve this.

items="{
    path: '{= ${appView>/dataPath}}',
    parameters: {
      $count: true,
      $$updateGroupId: 'peopleGroup'
    }