cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 Formatter issue

Former Member
0 Kudos

Hi,

I want to implement formatter for displaying a value.

I am getting errors when I use this.

<ObjectNumber number="{

            path: 'Clabs',

            formatter: function(value){

                return value;

            }

}"/>

It works fine when I do this

I am getting errors when I use this.

<ObjectNumber number="{

            path: 'Clabs'

}"/>

I have set this data-sap-ui-xx-bindingSyntax="complex" in my index page too.

Accepted Solutions (1)

Accepted Solutions (1)

mauriciolauffer
Contributor
0 Kudos

You can't declare javascript functions in a XMLView.

You should follow this guide to use Formatters:

https://sapui5.hana.ondemand.com/sdk/#docs/guide/482df92c6e8b429c8fc9022179515194.html

Former Member
0 Kudos

For some reason, I have to include this code

<script src="util/Formatter.js"></script>

in my index page. I am unsure why SAPUI5 is not reading the files in util folder automatically.

mauriciolauffer
Contributor
0 Kudos

You should include the following command at the beginning of your "*.controller.js" (the file which calls the formatter function):

jQuery.sap.require("yourapp.util.Formatter");

Answers (2)

Answers (2)

former_member182048
Active Contributor
0 Kudos

your trying to write javascript into XML

create a js formatter module outside of the XML

my.Formatter = {

     formatClabs : function(sClabs){

        return <logic here>

   }

}

then call your formatter like

<ObjectNumber number="{

            path: 'Clabs',

            formatter:'my.Formatter.formatClabs'

}"/>

look at the demokit examples for reference

hth

jsp

kedarT
Active Contributor
0 Kudos

Hi Senthil,

In your second case you do not need the formatter in that case do binding directly:

<ObjectNumber number="{Clabs}"/>

Hope this helps.

Regards,

Kedar

Former Member
0 Kudos

Kedar, the formatter is not working. If I have some other statements in the formatter function, they are also not working.