0
votes

Im a rookie in the SAPUI5 enviroment and with JavaScript. I use the Master Detail template, thereby are on the master page the Supplier displayed and on the detail page the products, which they produce. My goal is to display the number of products behind every supplier name on the master page. The products and the supplier are 2 entities and have an association. There is a function in my detail controller, which counts the table lenght and dispaly the variable on the detail page. How do i get this variable in my master page?

I tried it with OData operations, did not work cause of the dependence between the 2 entities.

I tried it with an Eventbus to get access to the count function from master to detail controller. Problems occured with the triggering of the event.

I tried display my function as an object and had a problem with the access of the varibles.

Do someone has a smart solution for my problem ? :)

Regards Felix

1
Why not to add count as a property to the supplier entity?slkorolev

1 Answers

1
votes

The easiest way to accomplish this is to have the OData service to do the heavy lifting for you. You should add an additional attribute to the Supplier entity containing the number of products.

The approach you described above, i.e. to transfer the count from the detail page to master page, doesn't really work, as the detail page only shows products of one supplier. In your question you stated that you want to display the count for all suppliers though. This would require you to run the logic in your detail page for all suppliers in your list.

If the number of products per supplier isn't that high, you could also think of expanding the products per supplier using /Suppliers?$expand=Products and add some logic to count the products per supplier when you receive the data (e.g. using the change event set while running bindElement). This will be terribly slow if you have a large number of products per supplier though, as all products per supplier are retrieved and downloaded and counted.

Another slow approach would be to fire a $count query to the OData service for every Supplier in your list. Although this causes less strain on the front-end, this may result in an even higher strain on the back-end running the OData service.

In your case, the counting alternative is unlikely to be a viable option. So I would try to extend the OData service if I were you.