onRender Event for a row?

Hi:

I have a table view, and I like to change the bgcolor of every row based on a column value. It works if I attach the method to the onRender event of all columns, but can I attach that method to de whole row?

Try attaching the code to the onRender event of the form.

I have this pseudo-code in the onRender method:

var rec = event.getRecord();
if(rec.field1 > 0) {
    event.getRenderable().bgcolor = globals.COLOR1;
} else {
    event.getRenderable().bgcolor = globals.COLOR2;
}

If I attach this method to every columns, it works fine, but (as you say) I attach this to the onRender event of the form, I receive this error: “Cannot read rec.field1 property…”

Yes you are right, that happens. What I use to do is check if event.getRecord() is valid before doing anything.

I´m not sure but I guess that this is because the record object only exists when the element being rendered is attached to an object, like a textfiled.

Try this:

var rec = event.getRecord();
if(rec){
   if(rec.field1 > 0) {
       event.getRenderable().bgcolor = globals.COLOR1;
   } else {
       event.getRenderable().bgcolor = globals.COLOR2;
   }
}