Skip to Content
0
May 12, 2018 at 01:05 PM

How to bind count value to a single property?

1884 Views

Hi experts,

I am currently working on single Tiles and want to add some count values from the Northwind oData Service.

The app contains just one view and one controller.
View:

<mvc:View
	controllerName="customtileapp.controller.CustomTile1"
	xmlns="sap.m"
	xmlns:mvc="sap.ui.core.mvc">
	<GenericTile class="sapUiTinyMarginBegin sapUiTinyMarginTop tileLayout" header="Country-Specific Profit Margin" subheader="Expenses" press="press">
		<TileContent unit="EUR" footer="Current Quarter">
		<NumericContent scale="M" value="{path: '/Customers', formatter: '.formatTile'}" valueColor="Error" indicator="Up" formatterValue="true" /> 
		</TileContent>
	</GenericTile>
</mvc:View>

Controller:

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


	var PageController = Controller.extend("customtileapp.controller.CustomTile1", {
		
		onInit: function() {
			this.oView = this.getView();
			this.oModel = new sap.ui.model.odata.v2.ODataModel("/northwind/V2/Northwind/Northwind.svc", true);
			this.oView.setModel(this.oModel); 
		},
		
		
		formatTile: function() {
			var counter;
				this.oModel.read("/Customers/$count", {async : true,
										success : function(oData, response) {
											counter = response.body;
											MessageToast.show(counter);
		}}); 
			return counter;


		}
	});


	return PageController;


});

The MessageToast inside the formatter Function works fine and shows the correct number of customers (91). But the number I want to show on the tile always shows 0.

Hope someone can help me :)

Best regards.

Attachments

unbenannt.jpg (15.9 kB)