Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Dynamic binding of items in sap.m.Table with OData expand

Hi everyone,

according to thread Dynamic binding of items in sap.m.Table using XML views and XSOdata Association i tried to implement the following scenario:

i have a table with ChargingOrders for Electric vehicles, that should be managed in time slots. For that i have the two tables ChargingOrders and LoadManagement. On my xml view i have two tables. If i click on an item of the ChargingOrders table, the corresponding entries in LoadManagement should be shown in the second.

Here is the relevant coding:

The *.xsodata file:

service namespace "FlexiForecast.services" {

    "A627603"."CHARGINGORDERS" as "ChargingOrders" navigates ("ManagedOrders" as "management");

    "A627603"."LOADMANAGEMENT" as "LoadManagement";

   

    association "ManagedOrders" with referential constraint principal "ChargingOrders"("LAID") multiplicity "1" dependent "LoadManagement"("LAID") multiplicity "*";

The second table in the view:

<Table id="idLoadManagement" visible="false" inset="false" items="{/LoadManagement}" growing="true" growingThreshold="5" growingScrollToLoad="false">

                   [...]

                    The columns

                   [...]

                    </columns>

                    <items>

                        <ColumnListItem>

                            <cells>

                                <ObjectIdentifier text="{LAID}" />

                                <Text text="{ARRIVAL}" />

                                <Text text="{DEPARTURE}" />

                                <ObjectNumber number="{PERFORMANCE}" unit="W" />

                            </cells>

                        </ColumnListItem>

                    </items>

                </Table>

The controller:

onItemSelected : function(oEvent) {

            var oSelectedItem = oEvent.getParameter("listItem");

            var oContext = oSelectedItem.getBindingContext();

            var sPath = oContext.getPath();

            var oTable = this.byId("idLoadManagement");

           

             var oTemplate = new sap.m.ColumnListItem( 

                      {cells: [

                              new sap.m.Text({text : "{LAID}"}),

                              new sap.m.Text({text : "{ARRIVAL}"}),

                              new sap.m.Text({text : "{DEPARTURE}"}),

                              new sap.m.Text({text : "{PERFORMANCE}"}) 

                              ] 

            });  

           

            oTable.bindItems(sPath + "?$expand=management", oTemplate);

            oTable.setVisible(true);

        }

No data can be retrieved. The error has to be in the way i set the path in the bindItems method, but i can not figure out, how to do it correctly.

I was able to make it work with a filter, but i do not think this is an appropriate approach.

Can you help me?

Thanks,

Tobias

Tags:
Former Member
Former Member replied

Exactly! your example was very helpfull! Thank you.

I had to bind the association element to the table.

View:

<Table id="idLoadManagement" visible="false" inset="false" items="{management}" growing="true" growingThreshold="5" growingScrollToLoad="false">

Controller:

onItemSelected : function(oEvent) {

            var oSelectedItem = oEvent.getParameter("listItem");

            var oContext = oSelectedItem.getBindingContext();

            var sPath = oContext.getPath();

            var oTable = this.byId("idLoadManagement"); 

          

            oTable.bindElement({path:sPath});

            oTable.setVisible(true);

}

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question