I want to build my own formattor for displaying the amount as it should in the different currencies.
One could guess I use this solution I already know:
<t:template>
<Text text="{
parts: [
{path: 'amount'},
{path: 'currency'}
],
type:'sap.ui.model.type.Currency',
formatOptions: {
currencyCode: false
}
}"
</t:template>
the problem with this solution is I already show the currency in a seperate column and if I go with this solution it looks pretty ugly....
so I tried this one:
<t:template>
<Text text="{parts: [
{path: 'amount'},
{path: 'currency'}
],
formatter : '.formatter.currency'}"
/>
</t:template>
and my formatter function looks like this:
currency: function(amount, currency) {
var change = [];
change.push(amount);
change.push(currency);
var sInternalType = "";
var amount1 = new sap.ui.model.type.Currency();
amount1.formatValue(change, sInternalType);
return amount1;
}
Here I would guess I do something completely wrong, as English is not my first language I would probably assume I didnt understood the API References right, as they is stated this:
If it is your intention not to show the currency symbol or code because you already show it elsewhere, you could simply set showMeasure
to false
, e.g.:
<Text xmlns:core="sap.ui.core"
core:require="{ CurrencyType: 'sap/ui/model/type/Currency' }"
text="{
parts: [
'amount',
'currency'
],
type: 'CurrencyType',
formatOptions: {
showMeasure: false
}
}"
/>
Not showing the currency code/symbol is a feature of the standard Currency type. You don't need to extend it.
Note: In case of OData V4, require the type sap/ui/model/odata/type/Currency
instead.