cancel
Showing results for 
Search instead for 
Did you mean: 

Formatter is not working

Former Member
0 Kudos

Hi All,

I'm trying to format values using formatter in table but it is not working and empty values are showing in table.

Please see my code and resolve my issue

In View:

.........

<items>

  <ColumnListItem press="onPress">

  <cells>

  <Text id="otext1" xmlns="sap.m" text="{value1}" />

  <Text id="otext2" xmlns="sap.m" text="{path:'value2' ,

  formatter : '.formatter.converter'}"/>

  <Text xmlns="sap.m" text="{value2}" />

  <Text xmlns="sap.m" text="{value3}" />

  <Text xmlns="sap.m" text="{value4}" />

In controller:

sap.ui.define([ "sap/ui/core/mvc/Controller", "chartswithxml/formatter" ],

 

function(Controller, formatter) {

  "use strict";

  return Controller

  .extend("chartswithxml.S1",

  {

  formatter : formatter,

  onInit : function() {

  var oModel = new sap.ui.model.odata.ODataModel("Odata model/");

  this.getView().setModel(oModel);

.........

Finally formatter.js

sap.ui.define([], function () {

  "use strict";

  return {

  converter : function (sConverter) {

  //var s = this.getView().getModel().getData();

  return sConverter/1000;

  }

  };

});

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

I resolved this issue by adding 'data-sap-ui-xx-bindingSyntax="complex"' to the bootstrap of SAPUI5 in index.html.

Regards,

Sai Ram Dinesh Pallapotu

Answers (3)

Answers (3)

former_member201620
Participant
0 Kudos

Can you confirm your formatter is actually loaded (check network tab of your dev tools)? Is there any error message appearing (check console tab of your dev tools)?

If so just put a breakpoint in your formatter and see what's happening.

Former Member
0 Kudos

Hi Christian,

I put the break point in the formatter but it is not executing and in network tab of chrome formatter is giving status code 200(OK).

Regards,

Sai Ram Dinesh

former_member201620
Participant
0 Kudos

If you set a breakpoint in your controller is this.formatter defined and referring to your Formatter?

Former Member
0 Kudos

I have put break point at controller and formatter both are not executing , that means from controller the control is not moving to formatter.

former_member201620
Participant
0 Kudos

Are you sure your controller is loaded? You did not forget controllerName in your view, did you?



<core:View xmlns:core="sap.ui.core"
   xmlns:m="sap.m"
   controllerName="com.demo.controller.App">

Put a breakpoint in your controllers onInit and check if Formatter is present there.

saurabh_vakil
Active Contributor
0 Kudos

Are you getting the correct value from the field value2 from the OData service? Just for testing this have you tried removing the formatter and just setting the value of the Text element by binding it to value2?

<Text id="otext2" text="{value2}" />


Also why are you declaring the sap.m namespace within the Text element declaration? just write xmlns="sap.m" in the root tag of your view.

Former Member
0 Kudos

Hi,

I have done what you are saying,without formatter declaration i'm able to get value. In output,I'm getting empty value only for field on which i'm applying formatter and remaining fields are working correctly.

Regards,

Sai Ram Dinesh

saurabh_vakil
Active Contributor
0 Kudos

In the converter function in the formatter.js file, check by putting a breakpoint in developer console sources tab in Chrome and check if the field value2's value is successfully getting passed to the function.

I have declared an ObjectIdentifier which calls a formatter function like below:


<ObjectIdentifier

  title="{path:'GrossAmount', formatter:'.formatter.converter'}"/>

The converter function in the formatter.js file is as below:


sap.ui.define([], function() {

  "use strict";

  return {

  converter : function(amnt) {

  return amnt/1000;

  }

  };

});

In the controller file:


sap.ui.define([

  "sap/ui/core/mvc/Controller",

  "sap/m/MessageToast",

  "com/demo/model/formatter"

], function(Controller, MessageToast, formatter) {

  "use strict";

  return Controller.extend("com.demo.controller.App", {

  //ColumnListItem's press event handler

  formatter:formatter,

With this I am getting the correct result.

saurabh_vakil
Active Contributor
0 Kudos

Can you try something like below and see if you are getting the correct result?


<Text id="otext2" xmlns="sap.m" text="{path:'value2', type: 'sap.ui.model.type.Float', formatOptions: {maxFractionDigits: 3}} />

Former Member
0 Kudos

I tried your suggestions, still i'm getting empty value in output

former_member203031
Contributor
0 Kudos

Hi Sai,

Already you set the path to the table,so i think there is no need to mention path again like this:

<Text id="otext2" xmlns="sap.m" text="{path:'value2' ,

  formatter : '.formatter.converter'}"/>

So please try this once :

<Text id="otext2" xmlns="sap.m" text="{value2 ,

  formatter : '.formatter.converter'}"/>

Hope it works.

Thanks,

Deepak.

Former Member
0 Kudos

Hi Deepak,

Thanks for reply. I tried your one but it is also not working

Regards,

Sai Ram Dinesh Pallapotu