Reputation: 25
I am trying to re-use the formatter methods used in the xml view but from the controller. This is because I need to export to excel a ui.table and the class sap.ui.export.Spreadsheet get data is it is in the JSON Model and not as it looks like after the applying the formatter in the xml View.
sap.ui.define([
"../controller/BaseController",
"../model/models",
"../model/formatter"
],
function (BaseController, models, formatter) {
"use strict";
return BaseController.extend("ns.controller.Main", {
formatter: formatter,
_formattedUiTableData: function (sCode){
return formatter.getStatusText(sCode);
}
});
});
/////////////////at formatter.js /////////////////////////////////////////////
sap.ui.define(["../controller/BaseController"
], function () {
"use strict";
return {
serviceCoderDescription(sCode) {
const oResourceBundle = this.getOwnerComponent().getModel("i18n").getResourceBundle();
switch (sCode) {
case "A":
return oResourceBundle.getText("CodeA");
case "B":
return oResourceBundle.getText("CodeB");
default:
return sCode;
}
}
};
});
Upvotes: 0
Views: 69
Reputation: 38
Can you try whether the following approach works?
return formatter.getStatusText.bind(this)(sCode);
You should also be able to use
this.oView.getModel("i18n").getResourceBundle();
instead of
this.getOwnerComponent().getModel("i18n").getResourceBundle();
Upvotes: 0
Reputation: 56
The fotmatter has its own context, so basically this
in formatter won't point to controller object.
To achieve this, you should change the context of the function call:
return formatter.getStatusText(sCode).bind(this)
Upvotes: 0