5

I have created a webservice and trying to bind data using oData protocol in SAPUI5.

I have created a table:

createContent : function(oController) {

      jQuery.sap.require("sap.ui.table.Table");

      //Create table control with properties

      var oTable = new sap.ui.table.Table({
          width : "100%",
          rowHeight : 50,
          title : "Lst of Items",
          selectionMode : sap.ui.table.SelectionMode.None
      });



      oTable.addColumn(new sap.ui.table.Column({
          label : new sap.ui.commons.Label({
          text : "PO Number"
          }),
          template : new sap.ui.commons.TextView({
          text : "{PoNumber}"
          }),
          }
      ));

      oTable.addColumn(new sap.ui.table.Column({
          label : new sap.ui.commons.Label({
          text : "Item"
          }),
          template : new sap.ui.commons.TextView({
          text : "{PoItem}"
          }),
          }
      ));

      //Filter values for a certain PO
      var aFilter = [];
      aFilter.push( new sap.ui.model.Filter("PoNumber", sap.ui.model.FilterOperator.EQ, "4500000043") );


      oTable.bindRows({
          path: "/PurchaseOrderItemCollection",
          filters: aFilter
          });


      return oTable;

}

The output should be as follows:

PONumber          POItem
4500000043        0010
4500000043        0020

But what I get is:

PONumber          POItem
4500000043        0020
4500000043        0020

So it shows the last item twice and doesn't show the first item. If I put a break point in my web service code then it is populated correctly.

The data model is created in the following way:

var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, false, "user", "passw");
   sap.ui.getCore().setModel(oModel);
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Radek
  • 1,403
  • 3
  • 25
  • 54

2 Answers2

3

I have encountered this. Problem is with your data model. Ensure that for the entity both PO number and PO item are marked as keys. Refresh any metadata cache, ensure that both properties appear as keys and try again. It should work.

Thanks Krishna

krisho
  • 1,004
  • 7
  • 26
2

My understanding is every entity/entry in the collection should have a unique id <entry><id>...</id></entry>. And in my case, the returned collection had no ids set for the entities. So the bound ui element finds multiple objects with same id (in this case empty id) and ends up displaying value which it finds the last.

The same should apply even if the id is same across all entities.

Hope it helps, if you have not already found what the problem is.

Thanks,

epsilonpsi
  • 3,753
  • 3
  • 17
  • 16