cancel
Showing results for 
Search instead for 
Did you mean: 

sap.m.table nodata

mantrishekar
Active Participant
0 Kudos

Hi All,

I am using northwind odata service to populate the data into sap.m.table

But ma unbale to display data into table.

am i doing anything wrong Please let me know

var oDataTable = new sap.m.Table();
oDataTable.addColumn(new sap.m.Column({header : new sap.m.Label({text : "Customer Id"})}));
oDataTable.addColumn(new sap.m.Column({header : new sap.m.Label({text : "Company Name"})}));
oDataTable.addColumn(new sap.m.Column({header : new sap.m.Label({text : "Contact Name"})}));
oDataTable.addColumn(new sap.m.Column({header : new sap.m.Label({text : "Contact Title"})}));
oDataTable.addColumn(new sap.m.Column({header : new sap.m.Label({text : "Address"})}));
oDataTable.addColumn(new sap.m.Column({header : new sap.m.Label({text : "City"})}));
oDataTable.addColumn(new sap.m.Column({header : new sap.m.Label({text : "Region"})}));
oDataTable.addColumn(new sap.m.Column({header : new sap.m.Label({text : "Postal Code"})}));
oDataTable.addColumn(new sap.m.Column({header : new sap.m.Label({text : "Country"})}));
oDataTable.addColumn(new sap.m.Column({header : new sap.m.Label({text : "Phone"})}));
oDataTable.addColumn(new sap.m.Column({header : new sap.m.Label({text : "Fax"})}));
//var serviceUrl = "https://cors-anywhere.herokuapp.com/services.odata.org/V2/Northwind/Northwind.svc/";
var serviceUrl = "https://cors-anywhere.herokuapp.com/services.odata.org/V3/Northwind/Northwind.svc/";
var oModel = new sap.ui.model.odata.ODataModel(serviceUrl,true);
sap.ui.getCore().setModel(oModel);
/*var jsonModel = new sap.ui.model.json.JSONModel();
oModel.read("/Customers",null,null,true,function(oData,response){
jsonModel.setData(oData);
});*/
//oDataTable.setModel(jsonModel);
var template = new sap.m.ColumnListItem({});
template.addCell(new sap.m.Text({text : "{CustomerID}"}));
template.addCell(new sap.m.Label({text : "{}"}));
template.addCell(new sap.m.Label({text : "{}"}));
template.addCell(new sap.m.Label({text : "{}"}));
template.addCell(new sap.m.Label({text : "{}"}));
template.addCell(new sap.m.Label({text : "{}"}));
template.addCell(new sap.m.Label({text : "{}"}));
template.addCell(new sap.m.Label({text : "{}"}));
template.addCell(new sap.m.Label({text : "{}"}));
template.addCell(new sap.m.Label({text : "{}"}));
template.addCell(new sap.m.Label({text : "{}"}));
//oDataTable.setModel(oModel);
oDataTable.bindItems("/Customers",template);

Regards,

Shekar

Accepted Solutions (1)

Accepted Solutions (1)

francesco_alborghetti
Active Participant
0 Kudos

Hi Shekar,

i am assuming you are using a proxy for testing odata service and avoid same origin error (https://cors-anywhere.herokuapp.com/), in that case your url should be fullProxyPath+fullServicePath:

var serviceUrl = "https://cors-anywhere.herokuapp.com/http://services.odata.org/V3/Northwind/Northwind.svc/";

you can check it here: https://jsfiddle.net/falborgh/17jwaf4h/

mantrishekar
Active Participant
0 Kudos

Hi Francesco,

I compared your github coding with my coding.

I found one difference i.e

i defined model as

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

but you defined that as below

var oDataModel = new sap.ui.model.odata.v2.ODataModel(serviceURL,true);

Could you please tell em the diffrence between definig in bothways and

other thing is

some odata services are defined as

var serviceURL = "https://cors-anywhere.herokuapp.com/http://services.odata.org/V2/OData/OData.svc/"

and some are

var serviceURL = "https://cors-anywhere.herokuapp.com/http://services.odata.org/V3/Northwind/Northwind.svc/";

Could you please let me know the difference between these two urls.

Regards,

Shekar

francesco_alborghetti
Active Participant
0 Kudos

Hi Shekar,

V2/V3/V4 identify OData specifications version.

Both sap.ui.model.odata.ODataModel and sap.ui.model.odata.v2.ODataModel supports version V2 of OData specifications, but sap.ui.model.odata.v2.ODataModel is the recommended one, more info here:

SAPUI5 SDK - Demo Kit

Two URLs you mentioned are OData test services, Northwind/Northwind.svc implements an extended data model, but it is read only service, OData/OData.svc is more simple, but it is possible to test in read/write mode (for generating full access read/write service you have to call this link:

http://services.odata.org/V3/(S(readwrite))/OData/OData.svc/

this will generate a full service like :

http://services.odata.org/V3/(S(00tbaomehxe3zchtzhiyendk))/OData/OData.svc/

that you can use for testing update/create/delete API).


V2/V3/V4 inside the URL identify the version of OData specification, SAPUI5 supports only V2 and V4, but V2 is still the recommended one for productive applications (V4 full support is still in development).


You can check the differences here:


SAPUI5 SDK - Demo Kit

Answers (1)

Answers (1)

vaibhav_gb
Explorer
0 Kudos

Try the following url

http://services.odata.org/V2/Northwind/Northwind.svc

and request with "/Customers"

regards

GB