Skip to Content
0
Nov 07, 2016 at 08:40 AM

Error in oData Model example

146 Views Last edit Nov 10, 2016 at 05:45 AM 2 rev

Hi Team,

I am trying to build a quick example for oData Model implementation by building a Table and fetching data from url "http://services.odata.org/V2/oData/oData.svc/". When I am running it , My table is getting displayed but data is not fetched.

Below i my code for Model, View and Controller.

Request you to rectify my mistake.

index.html

<!DOCTYPE HTML>

<html> <head>

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>

<script src="resources/sap-ui-core.js"

id="sap-ui-bootstrap"

data-sap-ui-libs="sap.ui.commons,sap.ui.table,sap.ui.model"

data-sap-ui-theme="sap_bluecrystal">

</script>

<script>

sap.ui.localResources("button");

var view = sap.ui.view({id:"idView11", viewName:"button.View1", type:sap.ui.core.mvc.ViewType.JS});

view.placeAt("content");

</script>

</head> <body role="application"> <div id="content"></div> </body> </html>

view

sap.ui.jsview("button.View1", { /** Specifies the Controller belonging to this View. * In the case that it is not implemented, or that "null" is returned, this View does not have a Controller. * @memberOf button.View1 */ getControllerName : function() { return "button.View1"; }, /** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed. * Since the Controller is given to this method, its event handlers can be attached right away. * @memberOf button.View1 */ createContent : function(oController) { //Create table var oTable = new sap.ui.table.Table("TAB1", { title : "Table using oData", visibleRowCount : 5, navigationMode : sap.ui.table.NavigationMode.Paginator }

);

var oColumn1 = new sap.ui.table.Column("C1",{ label : "ID", template : new sap.ui.commons.TextField().bindProperty("value","ID"), });

oTable.addColumn(oColumn1);

var oColumn2 = new sap.ui.table.Column("C2",{ label : "Name", template : new sap.ui.commons.TextField().bindProperty("value","Name"), });

oTable.addColumn(oColumn2);

return oTable;

} });

Controller:

onInit: function() {

//Create an oData Model

var oModel = new sap.ui.model.odata.ODataModel("proxy/http/services.odata.org/V2/oData/oData.svc/");

//Bind the table

var oTable = sap.ui.getCore().byId("TAB1");

//set model to the table oTable.setModel(oModel); oTable.bindRows("/Products"); },