cancel
Showing results for 
Search instead for 
Did you mean: 

How to bind two models to one control(UI5 Grid table)?

0 Kudos

My page has a UI5 Grid Table Control and it contains the following columns

  • Product Name
  • Product ID
  • Supplier Name
  • Supplier ID

Product and Supplier are two different entities which I fetch using different ODATA calls. (/Product and /Supplier) . The Product entity has Supplier ID as a foreign key. How would I display values from these entities in one single Grid Table?

P.S:

  1. This is not about one-way or two-way binding.
  2. Product and Supplier do not have a Parent - Child relationship

Accepted Solutions (0)

Answers (2)

Answers (2)

Joseph_BERTHE
Active Contributor
0 Kudos

Hello,

Redefine you OData model. I mean, create a Parent entity which contain properties :

  • Primary key (id or orther)
  • Product ID
  • Supplier ID

Then, create two children entities which refer to Product and Supplier. Then create an association (in the both way) for each ID (Product and Supplier).

For instance you Product entity should looks like this :

  • Product ID (the key)
  • Product Name

At the end, the request should looks likes this :

  • <path_to_serveur>/YOUR_SERVICE/ParentEntity?$expand=Products,Suppliers

Kind regards,

Joseph

junwu
Active Contributor
0 Kudos

what's the point? still two separate entity, how can he display them in one table?

Joseph_BERTHE
Active Contributor
0 Kudos

easy 🙂

In fact you have 3 entities types but never mind. The point is with expand property you can merge data. Look at this example :

In the view :

<mvc:View controllerName="ch.saphir.demo.expand.Demo_Expand_Table.controller.View1" xmlns:html="http://www.w3.org/1999/xhtml"
    xmlns:mvc="sap.ui.core.mvc" displayBlock="true" xmlns="sap.m">
    <App id="idAppControl">
        <pages>
            <Page title="{i18n>title}">
                <content>
                    <Table noDataText="Drop column list items here and columns in the area above" id="__table0"
                        items="{ 
                            path:'/MaterialListSet', 
                            parameters:{expand:'Units'}">
                        <items>
                            <ColumnListItem >
                                <cells>
                                    <Text text="{MatlDesc}"/>
                                    <Text text="{Units/Isotxt}"/>
                                </cells>
                            </ColumnListItem>
                        </items>
                        <columns>
                            <Column ><Text text="Material"/></Column>
                            <Column ><Text text="Unit Text"/></Column>
                        </columns>
                    </Table>
                </content>
            </Page>
        </pages>
    </App>
</mvc:View

Here Units is the navigation to the text of the Unit Code, and I call the expand in the parameters of the table Items aggregation.

In OData point of view, look at my screenshot :

Regards,

junwu
Active Contributor
0 Kudos

why not just conbine to one? why complicate it with association?

Joseph_BERTHE
Active Contributor
0 Kudos

Which binding do you want? I don't have coding anything for this. Only XML binding + Default OData model, that all.

Joseph_BERTHE
Active Contributor

In my point of view it is not more complicated, it is data modeling. Don't forget one thing, if we want to create simple application with Fiori concept, we need absolutely to take care of the data model. In that manner it will be very easy to reuse model and create hudge constellation of simple Fiori elements application combined with Fiori launchpad, you get the right things 😉

junwu
Active Contributor
0 Kudos

combine them to one entity and expose as service

ui control can be bound to n model, but it won't help for your case.