cancel
Showing results for 
Search instead for 
Did you mean: 

Bind oData to Table

tharaka_fernando
Contributor
0 Kudos

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..

Accepted Solutions (1)

Accepted Solutions (1)

ChandraMahajan
Active Contributor
0 Kudos

Hi,

Use OData model instead of jsonmodel.

    var oModel = new sap.ui.model.odata.ODataModel();


Also open chrome console (function key F12) and do the trouble shooting.


Regards,

Chandra



tharaka_fernando
Contributor
0 Kudos

Dear Chandrashekhar,

Thank you for your reply...

I have set my coding according to your guidance but in Chrome Im getting below error:

Uncaught TypeError: Cannot read property 'indexOf' of undefined

pfefferf
Active Contributor
0 Kudos

Hi Tharu,

did you define the service path pointing to the OData service when you create the ODataModel object (e.g. var oModel = new sap.ui.model.odata.ODataModel("http://www.mysite.com/services/myservice/", false); )?


You don't need the OData.request method call.


Please have a look to the API documentation (https://sapui5.hana.ondemand.com/sdk/#docs/api/symbols/sap.ui.model.odata.ODataModel.html).

Regards, Florian

tharaka_fernando
Contributor
0 Kudos

Hi Florian,

Appreciate if you could explain more..I am bit new to SAPUI5. I have written my coding as above.

there in the;

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

Anything further needs to be done?

pfefferf
Active Contributor
0 Kudos

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

Answers (0)