I've defined a new custom module:
status-app/formatter.js
sap.ui.define([], function() {
"use strict";
return {
stringToInt: function(value) {
console.log("Called: " + value);
return parseInt(value);
}
}
});
Then in my controller I defined it as dependency like in Step 23 of the walkthrough and added as controller property.
sap.ui.define([
"sap/ui/core/mvc/Controller",
"status-app/formatter"
], function (Controller, formatter) {
"use strict";
return Controller.extend("stibam-status.Main", {
//formatter: formatter,
formatter: {
stringToInt: function(value) {
console.log(value);
return "";
}
},
[...]
});
I've tried both variants of the code but the formatter is not called. I printed in my onInit-function this.formatter
but it was set correctly. Why is my view not calling my formatter only if I use a anonymous function in the view itself?
Not working
oColListItem.addCell((new sap.m.Text()).bindText({
path: "statusData>AnzPdf",
formatter: ".formatter.stringToInt"
}));
Working
oColListItem.addCell((new sap.m.Text()).bindText({
path: "statusData>AnzPdf",
formatter: function(value) {
console.log(value);
return parseInt(value);
}
}));