Page 1 of 1

Custom row background coloring

PostPosted: Thu Dec 13, 2012 10:16 pm
by mpwiedemann
Servoy 6.1

Row coloring in a table view is driving me crazy. This used to be easy with the old rowbackground calcs. Now, I'm just trying to color the background of a label based on the day of the week contained in another field using onRender . It works when the field is rendered, but it colors all the fields in every table row the same color until you move to a different day and then it changes all the rows to that color.

I have a pretty simple function using the value in the "day_name" field to determine the background color.

Code: Select all
function onShow_row_color(event) {
   
   
   if ( day_name == "Mon"){
      
      elements.row_color.bgcolor = "#D4D4FF";
      }
      else
   if ( day_name == "Tue"){
      elements.row_color.bgcolor = "#D1FFFF";
      }
      else
   if ( day_name == "Wed"){
      elements.row_color.bgcolor = "#C1FFC2";
      }
      else
   if ( day_name == "Thu"){
      elements.row_color.bgcolor = "#FFFFD4";
      }
      else
   if ( day_name == "Fri"){
      elements.row_color.bgcolor = "#FFE0C1";
      }
      else
   if ( day_name == "Sat"){
      elements.row_color.bgcolor = "#FFD4D4";
      }
      else
   if ( day_name == "Sun"){
      elements.row_color.bgcolor = "#DDC1AD";
      }
      else
   {
      elements.row_color.bgcolor = "#FFFFFF";
   }   
   
}

Re: Custom row background coloring

PostPosted: Thu Dec 13, 2012 10:44 pm
by Harjo
You need to get the element from the onRender event object

here is an example out of my head.....

Code: Select all
function onRender(event) {
   var _record = event.getRecord();
   var _element = event.getRenderable();
   if(_record) {
   var dayname = _record.day_name

   if ( day_name == "Mon" && _element == "row_color") {
      _element.bgcolor = "#ff0000"
      _element.fgcolor = "#ffffff"
   } else {
      _element.bgcolor = "#ffffff"
      _element.fgcolor = "#000000"
   }
}


Again I'm doing this out of my head, but you get the point...

Re: Custom row background coloring

PostPosted: Thu Dec 13, 2012 11:00 pm
by mpwiedemann
That did the trick. Thanks much!