cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to load the data from the Model onto the view using sap.ui.table.

Hi folks,

I want to display a simple table using XML views. I have a model which is loading the data from a JSON file. I am using 'sap.ui.table' and 'sap.m' class. The problem is I am unable to fetch the data onto the view. I think I am missing something with binding or loading the libraries or maybe in the bootstrap code.

Note: Look for the binding in the view:

Below are the code snippets :

1) Data.json

{
"empstr":

           {
		"eId": 100,
		"eName": "Prathamesh",
		"eSalary": 2400,
		"currency": "INR"
	},


	"empTab": [{
			"eId": 100,
			"eName": "Prathamesh",
			"eSalary": 2400,
			"currency": "INR"


		}, {
			"eId": 200,
			"eName": "Prateek",
			"eSalary": 2500,
			"currency": "USD"
		}, {
			"eId": 300,
			"eName": "Simar",
			"eSalary": 1200,
			"currency": "INR"
		}, {
			"eId": 400,
			"eName": "Sahil",
			"eSalary": 1350,
			"currency": "EUR"
		}, {
			"eId": 500,
			"eName": "Sakshi",
			"eSalary": 500,
			"currency": "USD"
		}, {
			"eId": 600,
			"eName": "Soumya",
			"eSalary": 12000,
			"currency": "INR"
		}, {
			"eId": 700,
			"eName": "Laxman",
			"eSalary": 240000,
			"currency": "INR"
		}


	]


}

2) Main.view.xml

<mvc:View xmlns:core="sap.ui.core" 
		  xmlns:mvc="sap.ui.core.mvc" 
		  xmlns="sap.m" 
		  xmlns:table="sap.ui.table"
		  controllerName="akhil.controller.Main"
	      xmlns:html="http://www.w3.org/1999/xhtml">
	
	 <table:Table id="myTab1"
	              selectionMode= "None" 
	              rows="{/empTab}">
      <table:title>
      	<Text text="Table header"></Text>
      </table:title>
            <table:columns>
            	
              <table:Column>
                <table:label>
                	<Label text = "Emp Id"></Label>	
                </table:label> 
                <table:template>
                	<Text text="{eId}"></Text>
                </table:template>
              </table:Column>
              
              
              <table:Column>
                <table:label>
                	<Label text = "Emp Name"></Label>	
                </table:label> 
                <table:template>
                	<Text text="{eName}"></Text>
                </table:template>
              </table:Column>
              
              
              <table:Column>
                <table:label>
                	<Label text = "Emp Salary"></Label>	
                </table:label> 
                <table:template>
                	<Text text="{eSalary}"></Text>
                </table:template>
              </table:Column>
              
              
              <table:Column>
                <table:label>
                	<Label text = "Currency"></Label>	
                </table:label> 
                <table:template>
                	<Text text="{/empTab/currency}"></Text>
                </table:template>
              </table:Column>
            </table:columns>   
          </table:Table>

</mvc:View>


3) Main.controller.js

 sap.ui.define([
	"sap/ui/core/mvc/Controller"
], function (Controller) {
	"use strict";


	return Controller.extend("akhil.controller.Main", {

		onInit: function () {
			
			var oModel = new sap.ui.model.json.JSONModel();
			oModel.loadData("/ExerciseBinding/Data.json");
			this.getView().setModel(oModel);
			
		}

	});


});

4) myhtml.html

<!DOCTYPE html>
<html>
	<head>
		<script id="sap-ui-bootstrap"		
		       	src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
				data-sap-ui-libs="sap.m, sap.ui.table"
				data-sap-ui-theme="sap_bluecrystal"
				data-sap-ui-bindingsyntax="complex"
				data-sap-ui-resourceroots='{
					"akhil": "./"
					}'
					>
					
		</script>	
	
		<script>
			var oView = new sap.ui.view({
				id:"idMain3",
				viewName:"akhil.view.Main",
				type: "XML"
			});

			oView.placeAt("XMLcontent"); 
		</script>
</head>
	
	<body class="sapUiBody">          
		<div id="XMLcontent"> 
		</div>
		</body>
</html>

5) Error

Uncaught Error: resource akhil/view/Main.view.xml could not be loaded from ./view/Main.view.xml. Check for 'file not found' or parse errors. Reason: Error: Invalid XML: <mvc:View xmlns:core="sap.ui.core" 
		  xmlns:mvc="sap.ui.core.mvc" 
		  xmlns="sap.m" 
		  xmlns:table="sap.ui.table"
		  controllerName="akhil.controller.Main"
	      xmlns:html="http://www.w3.org/1999/xhtml">
	

I am missing out something but can't figure out exactly what. I appreciate your feedback.

maheshpalavalli
Active Contributor
0 Kudos

Your xml code looks fine.. Maybe can you share the code using the plunker? similar to below

http://next.plnkr.co/edit/61W0eR42LzgSoDoo?preview

Accepted Solutions (1)

Accepted Solutions (1)

former_member182862
Active Contributor
0 Kudos

when you have

data-sap-ui-resourceroots='{
  "akhil": "./"
}'
and

var oView = new sap.ui.view({
  id:"idMain3",
  viewName:"akhil.view.Main",
  type: "XML"
});

then your Main.view.xml should be under view that's view/Main.view.xml

and your Main.controller should be under controller/Main.controller.js

Answers (0)