Skip to Content
avatar image
Former Member

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

Hi everyone,

according to thread and 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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Jul 05, 2016 at 05:03 PM

    Hi Tobias,

    You mean something like this? Plunker

    I used Northwind OData service for sample.

    Regards,

    Sai.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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);
      }