Custom row background coloring

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.

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";
	}	
	
}

You need to get the element from the onRender event object

here is an example out of my head…

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…

That did the trick. Thanks much!