1
votes

I've got a question regarding the binding of a sap.ui.comp.smarttable.SmartTable.

I have two Entities and thereby also two Entitysets, A and B.

A has 1-to-n relationship to B, ergo one instance of A can have (for example) 5 instances of B associated.

I can bind my SmartTable to either one of those without problem, but I want to bind it to e.g. A('7')/B, to only get items associated with the instance 7 of A. If I call that route in the browser, this works fine (so oData service works correctly).

However, I could not figure out how to bind the SmartTable accordingly. I tried tableBindingPath and entitySet in various attempts with different strings, but no luck.

Does anybody of you know to achieve this? We're using XML views but JS would also be fine.

2

2 Answers

6
votes

Since there is no code i will try my best to answer this . You need to bind A('7')/B .
For this the smart table's EntitySet=B(based on this the Smart Table will build the columns for you).
TableBindingPath should be name of the navigation property from A to B.
But for this work you should have set the model on the View which has Smart Table. Otherwise there will no data on the table.

Now there are 1 more property in smart table .
1. enableAutoBinding - If this is set to true then the smart table will automatically bind the data to the table.
2. If it is set to false you will need to call explicitly the method rebindTable on the Smart Table

A sample code snippet is shown below
SmartTable id="SmartTable" entitySet = "POItems" tableType="ResponsiveTable" enableAutoBinding="true" editable = "true" tableBindingPath="Items"

Here POItems is the name of the entity in service. Items is the name of the association from POHeaders (===> A from your example) to POItems(=====> B from your example)

Hope this helps.

Cheers, Veera

1
votes

In xml view you can do it with tableBindingPath simply like this:

<smarttable:SmartTable enableAutoBinding="true"  entitySet="B" tableBindingPath="/A('7')/C" ...

Where C is the name of the navigation property. Check that it is not "A('7')/C" or "/A/7/C"!

Dynamically you can do it with setTableBindingPath method i.e:

var id = "7";
this.getView().byId('smartTable').setTableBindingPath("/A('" + id + "')/C");

Moreover I didn't have to rebindTable.