on 09-12-2016 7:42 PM
Hi experts,
am new in using formatters,
i need to get value in percentage Example : 1600,1500 vales are there i need to get percentage value so 1600%1500*100 =106.6%
View.xml
<mvc:View controllerName="Formatter.controller.View1" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m">
<App>
<pages>
<Page title="{i18n>title}">
<content>
<List headerText="Information" items="{path: '/results'}">
<CustomListItem>
<VBox class="sapUiSmallMarginBegin sapUiSmallMarginTopBottom">
<HBox>
<Label text="Sales"/>
<Text text="{Sales}"/>
</HBox>
<HBox>
<Label text="Goal"/>
<Text text="{goal}"/>
</HBox>
<HBox>
<Label text="Percentage"/>
<!--<Text text="{parts: [{ path: '{Sales'},{ path: '{goal}'] formatter: 'formatter' }"/>-->
</HBox>
</VBox>
</CustomListItem>
</List>
</content>
</Page>
</pages>
</App>
</mvc:View>
formatter.js
sap.ui.define([], function () {
"use strict";
return {
calculation: function (a,b) {
return a*b%100;
},
};
});
controller.js
sap.ui.define([
"sap/ui/core/mvc/Controller",
'sap/ui/model/json/JSONModel',
], function(Controller, JSONModel) {
"use strict";
return Controller.extend("Formatter.controller.View1", {
onInit: function() {
var oModel = new JSONModel(jQuery.sap.getModulePath("Formatter.model", "/madhu.json"));
this.getView().setModel(oModel);
},
});
});
Please help,
Thanks in advance
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi sai,
am using web ide i created formatter.js under model folder
sap.ui.define([
] , function () {
"use strict";
return {
/**
* Rounds the number unit value to 2 digits
* @public
* @param {string} sValue the number string to be rounded
* @returns {string} sValue with 2 digits rounded
*/
numberUnit : function (sValue) {
if (!sValue) {
return "";
}
return parseFloat(sValue).toFixed(2);
},
var Formatter = {
Percentage: function(a, b) {
var oCalculation = (parseInt(a) / parseInt(b)) * 100;
return oCalculation.toFixed(2);
}
};
};
}
);
near var Formatter it showing unexpected identifier and do i need to add anything in controller
Hi
Use in this way
jQuery.sap.declare("retail.store.stockcorrection.YDMD_UI_COUNT.util.Formatter");
retail.store.stockcorrection.YDMD_UI_COUNT.util.Formatter = {
removeLeadZeros: function(value) {
if (value) {
var removeZeros = value.replace(/^0+/, '');
return removeZeros;
} else {
return value;
}
},
retail.store.stockcorrection.YDMD_UI_COUNT.util.Formatter in your folder stucture
Hi madhu ,
in the controller you need to tell that there is some formatter.js file which will format your data before attaching to view controls :
sap.ui.define([
"sap/ui/core/mvc/Controller",
'sap/ui/model/json/JSONModel',
"Formatter/util/Formatter"
], function(Controller, JSONModel,formatter) {
"use strict";
return Controller.extend("Formatter.controller.View1", {
formatter: formatter,
onInit: function() {
var oModel = new JSONModel(jQuery.sap.getModulePath("Formatter.model", "/madhu.json"));
this.getView().setModel(oModel);
},
});
});
and in the view please check your syntax .. it should be like this :
<Text text="{parts:[{path:'Sales'},{path:'goal'}],formatter:'.formatter.calculation'}"/>
your Formatter.js file is correct.
note:
my example above will find formatter file under util folder with name Formatter.js
thanks
Viplove
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.