Skip to Content

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

Bind oData to Table

Dear All Gurus,

Need your expert knowledge in solving below simple matter.


I have created an oData with Header and Line item values for Purchase Order details. And I am able to successfully consume oData Service with below code.


OData.request({ requestUri: "[server URL - this request is with oData $expand query]",

                   headers:{"X-Requested-With": "XMLHttpRequest",

                                "Content-Type": "application/atom+xml",

                                "DataServiceVersion": "2.0",      

                                "X-CSRF-Token":"Fetch"   },

                   method : "GET",                              

                user: "[User]",                                

                password: "[PW]" ,                           

                recognizeDates: true,

                         },

                         function (data, response){               // response is successful and values are coming in "data" variable

//Data needs to be bound to SAPUI5 table and Below is my Coding

    var oModel = new sap.ui.model.json.JSONModel();

sap.ui.getCore().setModel(oModel);

oModel.setData({modelData: data});

oTable1.setModel(oModel);

oTable1.bindRows("/modelData");

}

But this is not working...I know that I have done something wrong in binding data into table and expecting your valuable advice on this..

replied

Hi Tharu,

in the constructor of the ODataModel "class" you can add all information you need.

So your example should work nearly with following coding:

// create oDataModel and connect it to service

var oDataModel = new sap.ui.model.odata.ODataModel(<url to your service>, false, <user>, <password>);

// create table

var oTable = new sap.ui.table.Table();

// add a column to the table

oTable.addColumn(new sap.ui.table.Column({ label: new sap.ui.commons.Label({text:"Test Column Header"}), template: new sap.ui.commons.TextField().bindProperty("value", "<value of oData Model part of path bound to rows (see below)>") }) );

// set oDataModel for table

oTable.setModel(oDataModel);

// bind path of oDataModel to table rows

oTable.bindRows("<path>");

Regards, Florian

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question