Row Background Color

Example of alternating row background color calculation, also with different selected row color.

Example of alternating row background color calculation, also with different selected row color.
var index = arguments[0]
var selected = arguments[1]
if(selected) 
{ 
    return "#FFFFCC" 
} 
else 
{ 
    if(index % 2 == 0)
    { 
        return "#DCDCDC" 
    } 
    else 
    { 
        return "#F2F2F2" 
    } 
}

If you are using Servoy version 4.x, they added some additional parameters in the rowBGColorCalculation that allow you to change the color by column. Below is a simple example to illustrate that. So, you basically just create a calculation in your table, and then assign that calculation to the rowBGColorCalculation property on your table view form.

This is the basic example to change color by column. Just update the columnName1 and columnName2 with your values, and add additional case statements if needed.

var _rowindex = arguments[0];
var _isSelected = arguments[1];
var _field_type = arguments[2];
var _dataproviderid = arguments[3];
var _form_name = arguments[4];
var _state = arguments[5];
//comment these lines out after you are done
application.output("---start calc---")
application.output(_rowindex)
application.output(_isSelected)
application.output(_field_type)
application.output(_dataproviderid)
application.output(_form_name)
application.output(_state)
application.output("---end calc---")
//set specific by column
switch (_dataproviderid)//only the column must be colored
{
	case "columName1":
		return "#ff0000";
		break;
	case "columnName1":
		return "#00ff00";
		break;
	default:
		break;
}
return null
Next, this is a more advanced example where you can change the background color of the column based on the data in the column: (remember to update columnName1 with your column name.
var _rowindex = arguments[0];
var _isSelected = arguments[1];
var _field_type = arguments[2];
var _dataproviderid = arguments[3];
var _form_name = arguments[4];
var _state = arguments[5];
//set specific by column
switch (_dataproviderid)//only the column must be colored
{
	case "columnName1":
		if(columnName1 < 2)
			return "#ff0000";
		else
			return "#00ff00";
		break;
	case "columnName1":
		return "#00ff00";
		break;
	default:
		break;
}
return null