keshet
keshet

Reputation: 1826

SAPUI5 formatter function returns its parameter

I have a very strange issue with formatter function.

I have the following formatter:

_formatter: function(sAccessLevel){
    switch(sAccessLevel){
        case "fullAccess":
            return true;
        case "readOnly":
            return false;
        case "norefund":
            return false;
        case "nodiscount":
            return false;
        default:
            return false;
    }
},

for the following field:

<Column visible="{path: 'modelName>/Access', formatter: '_formatter'}" >
    <header hAlign="Middle" vAlign="Middle">
        <Text text="{i18n>discount}" textAlign="Center"/>
    </header>
</Column>

And in try-catch block I sometimes get the following error:

Error: "nodiscount" is of type string, expected boolean for property "visible" of Element sap.m.Column#__column154

or

Error: "fullAccess" is of type string, expected boolean for property "visible" of Element sap.m.Column#__column489

When I try to reproduce the error, the code works fine, but in production system's log I see the above error.

How this error possible?

Thank you.

Upvotes: 0

Views: 1328

Answers (1)

Naveen Kumar H S
Naveen Kumar H S

Reputation: 1304

Its a simple mistake. While giving the formatter in XML view we have to give the .formatterFunctionName as below.

<Column visible="{path: 'modelName>/Access', formatter: '._formatter'}" >
    <header hAlign="Middle" vAlign="Middle">
        <Text text="{i18n>discount}" textAlign="Center"/>
    </header>
</Column>

In the controller implement your formatter function as usual.

Upvotes: 2

Related Questions