Skip to Content
avatar image
Former Member

Unable to load data from Sample oData service in Ui5

Hello All,

I am trying to load sample oData service in my program

Sample oData

but when i am trying it is not getting load in my Table that is in my View.

view1.view.xml


<mvc:View controllerName="oData_Table.controller.View1" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc"
	displayBlock="true" xmlns="sap.m">
	<App>
		<pages>
			<Page title="{i18n>title}">
				<content>
					<Table id="idProductsTable" inset="false" items="{oModel>/PersonDetails}" >
						<headerToolbar>
							<Toolbar>
								<Title text="Student Info" level="H2"/>
							</Toolbar>
						</headerToolbar>
						<columns>
							<Column width="12em">
								<Text text="Person ID"/>
							</Column>
							<Column minScreenWidth="Tablet" demandPopin="true">
								<Text text="Age"/>
							</Column>
							<Column minScreenWidth="Tablet" demandPopin="true" hAlign="Right">
								<Text text="Phone"/>
							</Column>
							<Column minScreenWidth="Tablet" demandPopin="true" hAlign="Center">
								<Text text="Zipcode"/>
							</Column>
						</columns>
						<items>
							<ColumnListItem>
								<cells>
									<ObjectIdentifier title = "{oModel>PersonId}" />
									<ObjectIdentifier title = "{oModel>Age}" />
									<ObjectIdentifier title = "{oModel>Phone}" />
									<ObjectIdentifier title = "{oModel>Address/ZipCode}" />
								</cells>
							</ColumnListItem>
						</items>
					</Table>
				</content>
			</Page>
		</pages>
	</App>
</mvc:View>

And code for view1.controller.js

sap.ui.define([
	"sap/ui/core/mvc/Controller",
	"sap/ui/model/json/JSONModel",
	"sap/ui/model/odata/ODataModel"
], function(Controller, JSONModel, ODataModel ) {
	"use strict";


	return Controller.extend("oData_Table.controller.View1", {
	onInit: function() {


			// var oModel = new JSONModel();
			
			var oModel = new ODataModel("http://services.odata.org/V3/OData/OData.svc/", true);
			//oModel.loadData("http://services.odata.org/V3/OData/OData.svc/");
			//var jModel = new JSONModel(oModel);
			this.getView().setModel(oModel, "oModel");
		}
	});
});

What i need to do is.

  1. Loading "http://services.odata.org/V3/OData/OData.svc/" this data .
  2. Adding data it in table

Please Help me to solve this.

Best regards,

Urvish Panchal

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Mar 22, 2017 at 11:50 AM

    I think you are not having the reverse proxy config setup done. if not, there might be a cross origin error in your browser console. So i would recomend you to use webide and destination configuraiton which is the easiest way to avoid the cross origin issue.

    if you dont want to go for webide, you the below link:

    https://archive.sap.com/discussions/thread/3607977

    else use the below odata url, which will not give you cors error(try directly replacing you northwind with the below url):

    https://cors-anywhere.herokuapp.com/http://services.odata.org/V2/(S(frik5l2zde0sxh4jiifyhqo4))/OData/OData.svc/

    http://stackoverflow.com/questions/30318371/northwind-odata-service-not-working

    Best Regards,
    Mahesh

    Add comment
    10|10000 characters needed characters exceeded

    • Could you provide us the errors that were displayed in the console

      Best regards,

      Mahesh