1

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
pguddi
  • 325
  • 2
  • 3
  • 11

3 Answers3

6

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

Veeraraghavan N
  • 839
  • 1
  • 10
  • 19
  • Thank you! I was under the impression that I either have to set the tableBindingPath or the entitySet and not both. It works now as intended! – pguddi Aug 17 '15 at 08:11
  • @Veeraraghavan...thats fine I made a changes as entitySet="B" and tableBindingPath="Items" and enableAutoBinding="true" but what about "7" how should I only show the data associated with A(7). In my oModel I get whole set of entity A. How should I apply particular navigation property to smarttable – Zebronix_777 Mar 04 '16 at 10:31
  • Now A(7) is a entity and it has an association items which you need to bind to the smart table. All you need to do is Bind the view in which the smart table is present to A(7). As per this the binding is available to Smart table and since the content of the table is "items" the data will be filled. – Veeraraghavan N Mar 05 '16 at 23:40
  • If I need to add some filters when auto binding how can I do – tarzanbappa May 17 '18 at 11:21
1

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.

Konrad Grzyb
  • 1,561
  • 16
  • 12
0

For me I had the same scenario, only change that I needed to display the smartTable in a Fragment.

oDialog.bindElement({
                path: "/DetailSet('" + objectKey + "')"
});
                    
this.byID("SmartTable").setTableBindingPath("myExpandedEntitySet");
this.byId("SmartTable").rebindTable(true);
Ajay Gupta
  • 21
  • 1
  • 5