3.2.0

Row Color Based on Row Data Without Overriding Other Styles

Basically I want to set row color based on a flag in an array, but would still like built-in features like row selection colors to work. I've done something similar to the following but it breaks selected row highlighting. There is one entry in the matchFlag array for each data row in the table (data including match flag is all generated in PHP)

My code is based on this example
http://www.activewidgets.com/javascript.forum.12018.3/alternative-row-color-depend-of.html

var matchFlag [ 0, 1, 0, 0, 0 ];
var obj = new AW.UI.Grid;
obj.setSize(725, 300);
obj.setCellText(columnData);
obj.setHeaderText(columnHeaders);
obj.setColumnCount(12);
obj.setRowCount(// number of rows from data model);
obj.setSelectionMode("single-row");
// create new row property
obj.defineRowProperty("color", function(row){
    var color = "white";
    if(matchFlag[row] == 1) {
        color ="red";
    } else if(row % 2 == 0) {
        color = "#f2f4ff";
    } else if(this.getRowSelected(row)) {
        color = "blue";
    }
    return color;
})
// link row background to row color property
obj.getRowTemplate().setStyle("background", function(){
    return this.getRowProperty("color");
});
document.write(obj);
Steve
August 15,
I should add that row selection highlighting is broken with or without the code involving the selected row, I've tried it both ways.
Steve
August 15,
Nevermind, I figured out a MUCH easier way to do this by generating the style information in php.
Steve
August 15,

This topic is archived.

See also:


Back to support forum