Change Row Color in Portal

I have read all of the bgcolor post and tried a hundered different things but no dice on getting my background colors to change in my portal. I am using a calcualted field to makr whether a row is selected (1 or 0) and that works but neither of the following solutions worked.

First tried using this calc field servoy_row_bgcolor - but it only seems to analyse the first time the portal data is loaded not when the calc field “row_selected” is changed from 1 to 0 or 0 to 1.

if (row_selected == 0) 
 { 
   return '#FFFFFF'; 
 } 
else if (row_selected == 1) 
 { 
   return '#999900'; 
 }

Next tried including in my method for changing the “row_selected” field but no dice

if (products_groups_to_teams.row_selected == 1)
	{
	products_groups_to_teams.row_selected = 0;
	products_groups_to_teams.team.bgcolor="#FFFFFF";
	}
else
	{
	products_groups_to_teams.row_selected = 1;
	products_groups_to_teams.team.bgcolor="#000000";
	}

Thanks in advance

I am a little unsure how you are using this function. If you want to
change the back ground color of the row that you select in the portal then
this works:

On the form on which the portal is based set the Form Property
(RowBGColorCalculation) to your calculation. The calculation I use is the
one from the Servoy book:

var index = arguments[0];
var selected = arguments[1];
if (selected)
{
return “#6666ff”;
}

This works either on the form itself or when the rows are viewed in a
portal on the related form, i.e. every time you click/select a row that row
is assigned whatever background color you give it. If you just want to
assign a background color when a row is selected you don’t need to give
it a separate background color when it is NOT selected.

If on the other hand you want to have a calculation that highlights certain
rows based on some calculation then as an example this works:

var accDateTime = ipox_acc_date.valueOf();
var toDay = new Date().valueOf();
var diff = toDay - accDateTime;
var days = Math.floor(diff / (1000 * 60 * 60 * 24));
if ( days > 7 )
{
return “#ffcccc”;
}
else
{
return “#99ff99”;
}

Here I have a calculation that finds the difference in days between
today’s date and a field date. If there are more than 7 days then it gives
the background color a certain color, if less then it gives a different
background color.

HTH

P.S. While the second example certainly works, I did it last week along
with some other changes and found that the whole solution slowed down
a lot. I disabled all the changes because of this and haven’t gone back
yet to test if that is the cause.

John,

Thanks for the reply. I am using the portal as a multi-selection menu where the user can select, say 10 items out of 30 in the list. So I want them to be able to click on a row and that rows color changes and stays changed until they click on it again. To accomplish this I have a calcualted field that is defaulted to “0” and when they click on a row it changes the value to “1” - if they click on it again it sets it back to “0”. All I need is for the bgcolor of the individuals rows to be based on the “1” or “0” but this does not seem to work - I am guessing for 1 of 2 reason

  1. BGColors only calculate on the initial Portal load
  2. Calc fields cannot be referenced for bgcolor calcs

Any suggestions? What would work is an HTML like Multi-Select list box. I guess maybe I need to look into how to us Servoys HTML capabilities just not sure how to populate such an item or how to return the selected items as an array. I will start digging through the manuals but any addtional advice would be appreciated.

Thanks again.

Hi,

A couple of thoughts:

  1. BGColors only calculate on the initial Portal load

I don’t this is true because otherwise even the single selection wouldn’t
work and it definitely does as one goes through selecting different rows.

  1. Calc fields cannot be referenced for bgcolor calcs

On the calculation I sent earlier if I change the ipox_acc_date (one of the
variables that influences the background color) then the background color
will change when I leave the record after changing the date. So even if
a calculation field doesn’t work you can change a regular, integer field
through a method (onRecordSelection, yadda, yadda set the integer to 1
if it is 0 and vice versa) and that will certainly change the background
color as in my example at least on leaving that record. The Servoy guys
I’m sure might have better ways of doing it so that it is immediate on
selection (as in the first example of single selection) but ‘permanent’ per
user (as in the second example). Probably ‘saving’ the record as part
and parcel of the method would do that (and setting those integers to 0 to
start with in the method).

Actually I just thought of a problem in using a calc or a regular field for
this though. Unlike my situation where I have a limited number of users
and don’t have to worry about users selecting the same record, I imagine
in your case you do have to worry about that. So using a regular field or
a calculation field would affect the background color when more than one
user is selecting that row. I think you might have to go to using globals,
labels and/or html reporting to achieve that. I’m afraid that the html
way is over my head and experience at this point! :) But I imagine that
you could do a label that lies under the whole row and is invisible when
the row is not selected but becomes the ‘background’ color when the row
is selected through a method. This would make it unique for each user.

teammascot:

Saw this late, don’t know if you solved it or not.

Here’s the fomula that I’ve been using for quite a while:

var index = arguments[0]; // gets the index of the record
var selected = arguments[1]; //checks if this record is currently selected
if (selected)
{
return ‘#9999cc’// FMP Label Blue // Old Default Selected Grey ‘#999999
// FMP Grey ‘#cccccc
}
else if (bg_color == 1)
{
return ‘#ffff66
}
if (bg_color == 2)
{
return ‘#66ffff
}
if (bg_color == 3)
{
return ‘#ffcc66
}
if(bg_color == 4)
{
return ‘#ffffff
}

else
{
return ‘#ffffff’ // Default Grey
}
//‘#e0e0e0’ Servoy Default Grey

I set the color manually with a field in the table called, bg_color. They are set from 1 to 4 by colored buttons on the form each with a method attached called setBGColor01 to setBGColor04 which say:

bg_color = 1

No matter who looks at the form the colors remain until they are reset.

You could do all of this manually with onFocusedGained.

I hope this helps!