cancel
Showing results for 
Search instead for 
Did you mean: 

Formatter function is not defined..

Former Member
0 Kudos

Hi There,

I am getting error on following code:

Error - "test4odata" is not defined.

where I am doing wrong?

-----------------------------------------------------------------------------------------------

jQuery.sap.declare("test4odata.model.formatter");

sap.ui.define(function() {

  "use strict";

  test4odata.model.formatter = {

  status: function(Price) {

  if (Price == undefined) {

  try {

  var nPrice = Math.ceil(Price);

  if (nPrice < 10) {

  return "lower";

  } else if (nPrice > 10) {

  return "higher";

  } else {

  return "Error";

  }

  } catch (err) {

  return "None";

  }

  } else {

  alert("undefined");

  }

  }

  };

}, /* bExport= */ true);

------------------------------------------------------------------------------------

regards.

Laboni.

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member182372
Active Contributor
0 Kudos

post the code how you reference it, definition looks ok

Former Member
0 Kudos

this is my view

-------------------------------------------------------------------------

<mvc:View

controllerName="test4odata.controller.View1"

xmlns:html="http://www.w3.org/1999/xhtml"

xmlns:mvc="sap.ui.core.mvc"

xmlns="sap.m">

  <App>

  <pages>

  <Page title="{i18n>title}">

  <content>

  <Table

  items = "{/Products}">

  <columns>

  <Column>

  <Text text ="Rating"/>

  </Column>

  <Column>

  <Text text= "Price"/>

  </Column>

  <Column>

  <Text text= "status"/>

  </Column>

  </columns>

  <items>

  <ColumnListItem>

  <cells>

  <Text text = "{Rating}"/>

  <Text  text= "{Price}"/>

  <Text text = "{

         path: '/Price',

         formatter:'test4odata.model.formatter.status '

         }" />

  </cells>

  </ColumnListItem>

  </items>

  </Table>

  </content>

  </Page>

  </pages>

  </App>

</mvc:View>

------------------------------------------------------------

this is my controller file.

-----------------------------------------------------------

jQuery.sap.require("test4odata.model.formatter");

sap.ui.define([

  "sap/ui/core/mvc/Controller"

], function(Controller) {

  "use strict";

  return Controller.extend("test4odata.controller.View1", {

  onInit: function() {

  var oModel = new sap.ui.model.odata.ODataModel("/destinations/NorthwindV2/V2/OData/OData.svc",true);

  /* oModel.read('/Products', null, null, true, function(oData, oResponse){

  alert("fhhjfhjf");

  });

  */

  this.getView().setModel(oModel);

  

  }

  });

});

----------------------------------------------------

this is my index.html

-------------------------------------------------

<!DOCTYPE HTML>

<html>

  <head>

  <meta http-equiv="X-UA-Compatible" content="IE=edge" />

  <meta charset="UTF-8">

  <title>test4odata</title>

  <script id="sap-ui-bootstrap"

  src="../../resources/sap-ui-core.js"

  data-sap-ui-libs="sap.m"

  data-sap-ui-theme="sap_bluecrystal"

  data-sap-ui-compatVersion="edge"

  data-sap-ui-resourceroots='{"test4odata": ""}'>

  </script>

  <link rel="stylesheet" type="text/css" href="css/style.css">

  <script>

  sap.ui.getCore().attachInit(function() {

  new sap.m.Shell({

  app: new sap.ui.core.ComponentContainer({

  height : "100%",

  name : "test4odata"

  })

  }).placeAt("content");

  });

  </script>

  </head>

  <body class="sapUiBody" id="content">

  </body>

</html>

---------------------------------------------------------

this is my project structure.

former_member182372
Active Contributor
0 Kudos

try to move



jQuery.sap.require("test4odata.model.formatter");



into component