3.2.0

change link color dynamically not working

I have a function that looks at cell values and if they are a negative number it changes their color property to red.
This is working fine except for cells that have a AW.Templates.Link template set.

Here is my function:
var addNegativeColor = function (obj,cells) {
obj.refresh();
obj.defineCellProperty("color", function(col, row){
if(cells.contains(col))
{
var val = this.getCellData(col, row);
return val < 0 ? "red" : "blue";
}
return "black";
});

obj.getCellTemplate().setStyle("color", function(){
return this.getControlProperty("color");
});
};
Jonathan Doklovic
February 8,
I am confused... If you are basing a cell color on it's value and checking to see if it is a negative number, how do you expect it to work on a link? By definition, a link is not a number so any function used on it as a number would fail. Do you have a column that has mixed information in it?
Jim Hunter (www.FriendsOfAW.com)
February 8,
First to answer the above question, I'm using setCellData(myData) which contains unformatted numbers.
Then I'm applying the link with:
obj.setCellTemplate(new AW.Templates.Link, 16);
obj.setCellLink(function(c, r){return "ViewPaymentsMade.do?cycleID=" + myData[r][18];}, 16);

so in my color function, this.getCellData(col, row) actually returns the numeric value, not the link.

I've actually got it *mostly* working... just had to loop through the cells when getting the template:
var addNegativeColor = function (obj,cells) {
obj.defineCellProperty("color", function(col, row){
var val = this.getCellData(col, row);
return val < 0 ? "red" : "green";
});

for(var i = 0;i<cells.length;i++)
{
obj.getCellTemplate(cells[i]).setStyle("color", function(){
return this.getControlProperty("color");
});
}
};

This sets the color correctly, however, now when a row is highlighted the font remains the color set in my function, but it *should* turn to white like the default setting..... not sure how to accomplish this.
Jonathan Doklovic
February 8,

This topic is archived.

See also:


Back to support forum