Skip to Content

SAPUI5 - Control reference in formatter

Dec 08, 2016 at 10:48 AM


avatar image


I haven't asked a question here in like 5 years or so. So that means I'm really stuck...

In my SAPUI5 application, I cant to change the rotation of an icon depending on the value in the model. So I'm using a custom formatter, which takes in the model value. The custom formatter is in a separate formatter.js file. It's referenced in the view controller and it's being called correctly.

BUT! According to an old thread on StackOverflow, the "this"-reference should point to my uiElement. Which would be great, because that's exactly what I need to alter the rotation of the element. (thread: how-to-pass-control-reference-to-formatter-in-xmlview )

(there isn't a rotation property on an sap.ui.core.Icon, so please don't tell me that it's a bad idea to manipulate the uiControl from inside the formatter... )

Except that "this" apparently references my view controller, instead of my UI Element.


Please advise.


formatter-fun.png (62.4 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Tom Van Doorslaer Dec 08, 2016 at 01:56 PM

right, so here's the thing. it used to work. now it doesn't anymore.

Due to no viable solution to change the inline css style of an element via the formatter, I just created an extension of the source object, added a rotation property, and hacked the renderer.

works like a charm

arrow.png (707 B)
10 |10000 characters needed characters left characters exceeded
Jun Wu Dec 08, 2016 at 01:59 PM

you didn't follow it correctly

just use the full name(path) of the formatter, don't put it in your controller

Show 3 Share
10 |10000 characters needed characters left characters exceeded

I had actually already tried that, but that didn't work either.

Than my formatter was simply not recognized/found by the framework. (mind you, the path was quite definitely correct)

I've also tried inline binding (.bind(this) ) but that didn't go well either.

I've also tried to refactor my formatter to the old notation style AND call it via either full path specification or via controller mapping, but the former failed (again, framework couldn't find the formatter), and the latter still had the controller as self reference.

I'm not sure what the difference is between 1.40 and 1.34 that changed this behaviour.

Anyway, I got around it. Back to battle.

Tom Van Doorslaer

can you put the formatter as dependency in your controller or use $.sap.require?

it should work,

it is working for my case(1.28)

Former Member

It doesn't,

the latest libraries 1.40+ should have changed this behaviour;

and this is quite a big issue of the framework; i need to change the color of some input texts based on the text itself, and those input fields are column elements of a table, so they do not have preassigned Ids

the easy way would be a formatter function that add or remove some css class to the input control itself.

and also every change / livechange event is triggered only if the change is performed by the user, so from the view to the model; but if the model is updated by a webservice or by calculation and the model propagates the update to the view than no change event is triggered.

So my question is:
Do you have any solution to perform actions on a control based on dynamic changes of a property of the control itself??