cancel
Showing results for 
Search instead for 
Did you mean: 

CAP CDS with Fiori Elements UI: how to change Number Format Settings

Ben
Participant

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

timjones
Explorer
0 Kudos

Hi Ben,

Did you ever get a resolution for this.

If not did you use a particular workaround.

Any help would be much appreciated as experiencing the same issue and going round in circles :S

Cheers,

Tim J.

Ben
Participant
0 Kudos

Hi Tom

Unfortunately we do not have a proper solution for that.. would be interested if you can solve it too.

As workaround we define the Integer fields as String.. which is not good but at least we get rid of thousands separator..

Best regards,

Ben

timjones
Explorer

Same here we have been around the houses with it and String seems to be the only working option at the moment.

There was mention of Experimental IsCalendarYear in Common but had no luck yet as vscode completion doesn't find it even though it's in the documentation.

If I find anything other than string I'll post back her.

Cheers,

Tim J.

Accepted Solutions (0)

Answers (2)

Answers (2)

coffeehacker
Employee
Employee

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.

sap_newbie
Advisor
Advisor
0 Kudos
Thank you this worked !
pierre_fritsch
Explorer
0 Kudos

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.Cheers
Pierre
Rohit_Patil
Explorer
0 Kudos
pierre.fritsch

hello

I have a similar requirement as above if anyone found a solution plz do share. thanks in advance