I have a database consisting of customers and prospects (identified by the field company_type of ‘Customer’ or ‘Prospect’). These companies are displayed in a portal.
I would like to set the background colour for the prospect company rows with a particular colour, and the customers rows in a different background colour.
Is this possible, and if so, some help on how it can be achieved would be very useful.
variation…(alternate row colors and highlight active record)
var recordIndex = arguments[0]; // gets the index of the record
var selected = arguments[1]; //checks if this record is currently selected
if (selected)
{
return '#CCCCEE';
}
else
{
if (recordIndex % 2 == 0)//alternate on even oneven
{
return '#0000FF';
}
else
{
return '#FF0000';
}
}
…although the coloring works pretty rigidly throughout the solution.
(even in form view, which is not really desirable)
Is on planning for fine tuning.
I have got this working even in detail forms. But it is not consistent.
I will set a global variable isFormList = 1 whenever I move to a list layout.
the servoy_row_bgcolor calc is as follows:
var index = arguments[0]
var selected = arguments[1];
if (globals.isFormList == 1) {
if (selected) {
return globals.currentRowColor;
}
else {
if (index % 2 == 0) {
return globals.rowColor1;
}
else {
return globals.rowColor2;
}
}
}
Most of the time it works but some times the background of the detail forms also get changed. I am unsure that this is a refresh problem in the calculation. If it is the refresh problem then how can I overcome it?
It seems that the workaround for the calculation refresh problem is to goto someother record and return back to the original record. Then it works fine. But this workaround seems weird. Can the refresh of the calculation be done automatically whenever there is a layout navigation?
Do you mean with a details view the record view? Because the servoy_row_bgcolor isn’t even touched in a record view. We don’t set the background in a record view.
in 2.1 forms and portals have a special property where you can choose the bgcolor calculation of that specific form or portal. So it only works for that form or that portal, And you can have 2 forms that do different coloring even if they are based on the same table.
Is there any way to create a button that triggers this calculation and permanently sets it until user input changes it? Similar to coloring a row in excel.
What I mean is: you click the button and the action event will trigger a method that sets a global to a certain value 1,2 or 3 or whatever. Maybe even better, the global holds the desired color.
You create the calculation to change/set the rowbackgroundcolor and that calculation refers to the global and based on the name or color the color of the row background will change.
I have a field/column on my form called bg_color, set to uneditable. I have four buttons on my form that set this field via onAction to the numbers 1,2,3 or 4, depending on the button you hit. Each of those four buttons is colored differently for user reference.
Under Calculations, for the reserved named calc: servoy_row_bgcolor, I used the following formula:
var index = arguments[0]; // gets the index of the record
var selected = arguments[1]; //checks if this record is currently selected
if (selected)
{
return ‘#999999’
}
else if (bg_color == 1)
{
return ‘#ffff66’
}
if (bg_color == 2)
{
return ‘#66ffff’
}
if (bg_color == 3)
{
return ‘#ffcc66’
}
if(bg_color == 4)
{
return ‘#e0e0e0’
}
else
{
return ‘#e0e0e0’
}
So, I have a color that represents the currently selected row (syntax as provided by the wonderful Servoy examples) and then, depending on what number the column/field bg_color is set to, I have four colors that I use to continuously highlight rows that I want predesignated as one of those colors.
I hope I was thorough enough in documenting this for anyone else (read: newbie like me) to try this.