cancel
Showing results for 
Search instead for 
Did you mean: 

Change background color of Combo box item records

former_member303384
Discoverer
0 Kudos

I get the combo box items based on Odata entity set. In the same set, I have RGB values for each record and a name column. In the combox box , I need to show this name column as drop down with background color based on its corresponding RGB values.

RGB values are not fixed, they vary based on the backend data.

How to achieve this.

Accepted Solutions (0)

Answers (2)

Answers (2)

anborck
Participant
0 Kudos

Hello,

you can only achieve this with CSS.

First you need an event delegate for the onAfterRendering event:

var yourComboBox = this.getView().byId("<your id from the XML view>");
if (yourComboBox.aDelegates.length == 0) {
    // only add event delegate once
    yourComboBox.addEventDelegate({
	onAfterRendering: this.onAfterRendering.bind(this)
    });
}

Then you can implement the function on your controller:

onAfterRendering: function (obj) {
    var yourComboBox = obj.srcControl;

    // here you need to determine the id from the html dom element 
// you can use yourComboBox.getId() to achieve this // change the css by using jQuery: $(yourId).css(....); }

Hope this helps.

Andre

If anyone knows a more elegant solution to limit the event delegation to 1, please let me know.

SergioG_TX
Active Contributor
0 Kudos

have you tried adding this as a css class so the color can update automatically based on the odata value and a css class?