Reputation: 3
I am using a normal formatter to format all relevant columns in a simple UI5 Table. However, one column requires a more complex conversion where the comparison data is coming from the database which have already retrieved into an array. This array is already declared as a global variable with a 'this' value which can be used globally.
However, when I want to use this in the formatter function, this is undefined, and the 'this' control is referring to the internal formatter function. I am unable to refer to any global controller variable at all.
The formatter is called during a bindProperty function which I try to pass the array as a parts parameter, but unfortunately I am getting errors, passing parameters seems to be string components only.
Is there a way to use external array data or model in a formatter or passing them to it.
Tried to pass array value through bindParameters using parts.
var that = this;
bindProperty(
"text", {
parts: [{ path: 'AA' },
{ path: 'A'},
{ path: that._C}],
{ path: that.array},
formatter: that.columnFormatter
This raise a binding error.
In the formatter, The formatter function is not a separate file but is just a function in the controller.
Tried direct reference to the array in the formatter. E.g. this.array -> get undefined
Upvotes: 0
Views: 142
Reputation: 56
The formatter function has its own context by default, so this
points to the context of your function and not to the controller object. In your piece of code you can try to change the context of the formatter function in the following way:
formatter: that.columnFormatter.bind(that)
Upvotes: 0