cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 - Odata with Association sap.m.Table Binding in detail view

Ramesh
Explorer
0 Kudos

Hi,
I created a Master-Detail split app with Plant as a ComboBox in the Master View. I am able to bind the odata dataset for the Plant in Mater View but when I select the plant I want to show related storage locations in a table in the Detail View. In order to fetch the storage locations I created an association and the url looks something like this when I pick the plant '1001'  /../sap/ou/odata/sap/Z_PLANT_SLOC_SRV/PlantSet('1001')/PlantToSLoc  and resultant dataset is 'SLocSet'. I build the routes in the component.js and I am using xml view with sap.m. library.

I am not seeing any data binding in the detail view table not sure how to pass the association name in the route pattern. Currently my code in the


Master View

rowChange: function(evt){

var contect = evt.getParameter("selectedItem").getBindingContext("plantModel")+" ";
var path   = context.split("/")[1];
this._oRouter.navTo("Detail",{contextPath:path});

}


**In the path variable this is what I have "PlantSet('1001')"

Component.JS

routes:[
         subroutes: [

                         pattern: "{contextPath}",

                         name: "Detail",
                         view: "DetailView",

]

init: function() {

     oModel instantiation....
}

DetailView.view.xml
<Table id="itTabSloc" items="{plantModel>/SLocSet}'
     <columns>

          <Column>
               <Text text="Plant"/>

          </Column>

          <Column>
               <Text text="Sloc"/>

          </Column>

          <Column>
               <Text text="Desc"/>

          </Column>

     </columns>

    <items>

          <ColumnListItem>

               <cells>

                    <Text text="{plantModel>Werks}"></Text>

                    <Text text="{plantModel>Lgort}"></Text>

                    <Text text="{plantModel>Lgort}"></Text>

               </cells>

          </ColumnListItem>
   </items>

DetailView.view.JS

onInit: function() {

     this._oRouter = sap.ui.core.UIComponent.getRouterFor(this);
     this._oRouter.attachRoutePatternMatched(this._handleRouteMatched,this);

},

_handleRouteMatched: function(oEvent) {

     var oParameters = oEvent.getParameter("name");

     if(oParameters!="Detail"){ return;}

     var path = oEvent.getParameter("arguments").contextPath;

     path= "/"+path;

     this.getView().bindElement(path);

     this.getView().byId("TabId").bindRows(path+'/PlantToSLoc');

}


Thanks

Accepted Solutions (1)

Accepted Solutions (1)

saivellanki
Active Contributor
0 Kudos

Hi Ramesh,

Two things, I see a problem:

1. Typo in the rowChange event: contect should be 'context'


var context = evt.getParameter("selectedItem").getBindingContext("plantModel")+" ";

var path   = context.split("/")[1];

this._oRouter.navTo("Detail",{contextPath:path});


2. You're using a model name. When you use bindElement method, you have to mention model name as well, something like this:


onInit: function() {

   this._oRouter = sap.ui.core.UIComponent.getRouterFor(this);

   this._oRouter.attachRoutePatternMatched(this._handleRouteMatched,this);

},

_handleRouteMatched: function(oEvent) {

   var oParameters = oEvent.getParameter("name");

   if(oParameters!="Detail"){ return;}

   var path = oEvent.getParameter("arguments").contextPath;

   path= "/"+path;

   this.getView().bindElement({

      path: path,

      model: "plantModel"

    });

   //  this.getView().byId("TabId").bindRows(path+'/PlantToSLoc');

}

Here is a sample using Northwind OData service: Plunker

Regards,

Sai.

Ramesh
Explorer
0 Kudos

Hi Sai,
Thanks for your response appreciate your time I am using firefox browser and I tried to implement pretty much in line with the sample you provided but still not getting the binding to the table in the detail view. I am attaching the files if you can visually see any thing I am doing wrong please let me know.

Ramesh
Explorer
0 Kudos

Contd.. had to attach as txt files

Ramesh
Explorer
0 Kudos

ok, please ignore my last question I realized that I was not using the association name rather was using resultant dataset from oData model once I changed it worked like charm. Said thanks for your answer it was very helpful!

Answers (0)