on 08-26-2020 8:07 AM
Hi All
When serving a UI with Fiori Elements (sap.fe.templates, SAPUI5 Version 1.81.0) based on a CAP CDS Service, is it possible to change Number Format Settings?
For example for a Number (CDS Type Integer) to be formatted without thousands separator?
Best regards,
Ben
I worked around the problem by creating a service that returned two columns: the integer (order number in my case) as well as the string representation of the integer. The CDS looked something like this
service MyService {
entity MyEntities as select from db.MyEntities {
orderNumber as orderNumber, // the original field
cast(orderNumber as String) as orderString : String // cast and type works
} }
In my first attempt, I tried
service MyService {
entity MyEntities as select from db.MyEntities {
orderNumber as orderNumber, // the original field
orderNumber as orderString : String // type only won't work
} }
This worked whenever I created new entity instances, but it broke whenever I tried to update the instance. Adding the cast to the new column in addition to typing it as String resolved the problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tim and Ben
I faced this issue as well when trying to display a column representing a year.
entity MyEntity @(cds.autoexpose): cuid, managed {
@mandatory year: Integer @assert.range: [ 1, 9999 ];
// ...
}
I needed the @UI.LineItem
to display e.g. 2021, but it displayed 2,021 instead.
I couldn't find a native CAP solution yet, so I ended up with the workaround of adding a custom column:
Introduce a custom column yearColumn.fragment.xml
:
<core:FragmentDefinition xmlns:core="sap.ui.core" xmlns="sap.m">
<Text
text="{
path: 'year',
type: 'any',
formatter: 'handler.keepOnlyNumericCharacters'
}"
core:require="{handler: 'path/to/ext/NumberToUnformattedString'}"/>
</core:FragmentDefinition>
along with a formatter NumberToUnformattedString.js
:
sap.ui.define([], function () {
"use strict";
return {
keepOnlyNumericCharacters: function (sFormattedNumber) {
// `year` comes in already formatted as "2,021"...
return sFormattedNumber.replace(/\D/g, "");
}
};
});
and register the custom column in manifest.json
, under the corresponding targets
entry, in the subpath options
> settings
:
"controlConfiguration": {
"@com.sap.vocabularies.UI.v1.LineItem": {
"columns": {
"year": {
"header": "{{year}}",
"template": "path.to.ext.yearColumn",
"properties": ["year"],
"horizontalAlign": ["Right"],
}
}
}
}
I'm not sure whether that would work for all locales, but for the time being it does the job for my use case. I still hope someone else will come up with a better solution though.CheersYou must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
9 | |
9 | |
6 | |
6 | |
6 | |
5 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.