Custom row background coloring

Questions and answers for designing and implementing forms in Servoy

Custom row background coloring

Postby mpwiedemann » Thu Dec 13, 2012 10:16 pm

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";
   }   
   
}
mpwiedemann
 
Posts: 49
Joined: Sun Jun 01, 2003 9:08 pm
Location: Seattle, WA

Re: Custom row background coloring

Postby Harjo » Thu Dec 13, 2012 10:44 pm

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...
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: Custom row background coloring

Postby mpwiedemann » Thu Dec 13, 2012 11:00 pm

That did the trick. Thanks much!
mpwiedemann
 
Posts: 49
Joined: Sun Jun 01, 2003 9:08 pm
Location: Seattle, WA


Return to Forms

Who is online

Users browsing this forum: No registered users and 5 guests

cron