3.2.0

AW.UI.Combo() Conditional Item Color

Hi,

Assume I have available a database returning a recordset with two columns: the name of a group and how many people are in it. I have a combo box that where I want any given item to be the name of the group and to appear in red if the number of people is zero.

How would one set the color of some items in a combo box's list based on an associated value?

Thanks.
Paul Tiseo
April 21,
Paul,

you should define additional 'color' property in the Item data model and assign the value of the 'color' property to the item style color attribute -

var obj = new AW.UI.Combo;

    obj.setItemText([1, 2, 3]);
    obj.setItemCount(3);

    obj.defineItemProperty("color", ["red", "green", "blue"]);

    obj.getItemTemplate().setStyle("color", function(){
        return this.getItemProperty("color");
    });

    document.write(obj);



You may also use functions to link to the data instead of array.
Alex (ActiveWidgets)
April 21,

So, if I understand correctly, I have my dropdown items in an array called myGroupsVals. (The array is obviosuly generated in the page script.)

I need another array that I would pass as the second parameter in defineItemProperty, correct?

Thanks.
Paul Tiseo
April 21,
Correct.

Or you can use single 2-D array and link to it with the functions -

var myItems = [
        ["item1", "red"],
        ["item2", "green"],
        ["item3", "blue"]
    ];

    var obj = new AW.UI.Combo;

    obj.setItemText(function(i){return myItems[i][0]});
    obj.setItemCount(3);

    obj.defineItemProperty("color", function(i){return myItems[i][1]});

    obj.getItemTemplate().setStyle("color", function(){
        return this.getItemProperty("color");
    });

    document.write(obj);
Alex (ActiveWidgets)
April 21,

Gotcha, thanks.
Paul Tiseo
April 21,

This topic is archived.

See also:


Back to support forum