How to use rowBGColorCalc

Home for older / inactive topics

How to use rowBGColorCalc

Postby Jan Blok » Mon Jun 30, 2008 11:11 am

Make a calculation like:
Code: Select all
var index = arguments[0]
var selected = arguments[1]
if(selected)
{
   return "#FFFFCC"
}
else
{
   if(index % 2 == 0)
   {
      return "#DCDCDC"
   }
   else
   {
      return "#F2F2F2"
   }
}


Attach this to rowBGColorCalc form property

Since Servoy 4.0 its also possible to use a global method returning colors.
Jan Blok
Servoy
Jan Blok
 
Posts: 2684
Joined: Mon Jun 23, 2003 11:15 am
Location: Amsterdam

Postby jcompagner » Tue Jul 08, 2008 2:57 pm

When using a global method or calc the parameters should be pretty equal it doesnt make much sense that those are completely out of sync of each other.

In 4.0 they are this:

Calc:

rowindex (Integer), isSelected (Boolean), field_type (String), field_name (String)

Global:

rowindex (Integer), isSelected (Boolean), field_type (String), field_name (String), form_name (String), state (Record)

everything is possible to color, even individual cells (in tableview)

field_name and field_type are only filled in for a TableView in ListView/RecordView those are null.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby sanneke » Fri Jul 11, 2008 10:30 am

This is an example, where you have normal rowbg coloring and the empty fields are colored red.

Code: Select all
function bg_method()
{
   var _rowindex = arguments[0]
   var _isSelected = arguments[1]
   var _field_type = arguments[2]
   var _field_name = arguments[3]
   var _form_name = arguments[4]
   var _state = arguments[5]
      

   if(_state[_field_name] == null)
   {
      return "#FF0000"
   }
                          
   if(_isSelected)
   {
      return "#FFFFCC"
   }
   else
   {
      if(_rowindex  % 2 == 0)
      {
         return "#DCDCDC"
      }
      else
      {
         return "#F2F2F2"
      }
   }
         
}
Sanneke
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
sanneke
 
Posts: 383
Joined: Thu Jun 15, 2006 9:20 am
Location: Amersfoort

Postby sanneke » Fri Jul 11, 2008 10:46 am

I forgot to mention, this only works if the fieldname is equal to the dataprovider name.
Sanneke
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
sanneke
 
Posts: 383
Joined: Thu Jun 15, 2006 9:20 am
Location: Amersfoort

Postby sanneke » Fri Jul 11, 2008 11:20 am

if you want to give your column a different name, you can use:
Code: Select all
function bg_method()
{
   var _rowindex = arguments[0]
   var _isSelected = arguments[1]
   var _field_type = arguments[2]
   var _field_name = arguments[3]
   var _form_name = arguments[4]
   var _state = arguments[5]
   
   var _dataProviderName = forms[_form_name].elements[_field_name].getDataProviderID()
   if(_state[_dataProviderName] == null)
   {
      return "#FF0000"
   }
                          
   if(_isSelected)
   {
      return "#FFFFCC"
   }
   else
   {
      if(_rowindex  % 2 == 0)
      {
         return "#DCDCDC"
      }
      else
      {
         return "#F2F2F2"
      }
   }
         
}
Sanneke
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
sanneke
 
Posts: 383
Joined: Thu Jun 15, 2006 9:20 am
Location: Amersfoort

Postby jcompagner » Wed Jul 16, 2008 1:53 pm

for the final of 4.0 we had to change 1 parameter you get. Because the field_name wasnt a good idea because this gives people the idea that they can touch the elements like sanneke dit above.

Code: Select all
forms[_form_name].elements[_field_name].getDataProviderID()


But this is wrong in a bg calc/method you shouldnt touch elements just data so now the field_name is just the dataproviderid so you can do directly


Code: Select all
var dataproviderid= arguments[3]
if (_state[dataproviderid] == null) {xxx}
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby sanneke » Wed Jul 16, 2008 1:56 pm

so it will be

Code: Select all
function bg_method()
{
   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]
   
   if (_state[_dataproviderid]
   {
      return "#FF0000"
   }
                         
   if(_isSelected)
   {
      return "#FFFFCC"
   }
   else
   {
      if(_rowindex  % 2 == 0)
      {
         return "#DCDCDC"
      }
      else
      {
         return "#F2F2F2"
      }
   }
         
}
Sanneke
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
sanneke
 
Posts: 383
Joined: Thu Jun 15, 2006 9:20 am
Location: Amersfoort

Re:

Postby Riccardino » Sat Nov 29, 2008 9:06 pm

[quote="jcompagner"]
everything is possible to color, even individual cells (in tableview)
[/quote]
Is it also supported in WebClient? I'm having two different behaviours, depending on the kind of client I'm using (in SmartClient the coloring of a column works, but in WebClient I can only change the color of the entire row.
The code I'm using is:
function rowBg()
{
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];
if (_form_name == "richieste_elenco") {
switch (_state[_dataproviderid])//only the column must be colored
{
case "in attesa":
return "#fffa84";
break;
case "annullata":
return "#a0ff28";
break;
default:
break;
}

}
if (_state["status"] == "completata") // in this casa the entire row must be colored
{
return "#ecf0f0";
}
if (_isSelected) {
return "#b5d5ff";
} else {
if (_rowindex % 2 == 0) {
return "#ffffff";
} else {
return "#ffffcc";
}
}
}
User avatar
Riccardino
 
Posts: 911
Joined: Thu Apr 24, 2003 11:42 am
Location: Ferrara, Italy

Re: How to use rowBGColorCalc

Postby john.allen » Tue Dec 02, 2008 1:47 am

Any reason it the field/column coloring is only supported in tableview? I think I understand why it wouldn't work in list view (and anyway those are similar at least in terms of the number and style of column/row presentation). But I'd think it would be easier to do in record view than in table view and there would be a number of nice uses for that in record view when you having the user do inserts/updates of records and want to highlight empty fields in particular. Any chance of that getting added? Should I submit a request? (In other words is it possible?)

John
john.allen
 
Posts: 515
Joined: Wed Jul 02, 2003 10:07 pm
Location: Stanford CA USA

Re: How to use rowBGColorCalc

Postby jcompagner » Wed Dec 03, 2008 1:55 pm

Web client cant do individual coloring (yet)

Maybe we can improve that in a further version but now we really color the row tag. Then we have to rewrite that
The problem is also then when do you expect to be able to change the colors? All the time? for example when you enter/leave a field? The overhead can be quite large then.

john: Because in List or Record view we dont really have a event per field, we could have something like that but then the same thing as with the web applies
when do you want to be able to change it? Field enter/leave or really only when a record is set?

You could always create a case for this with a good use case description
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: How to use rowBGColorCalc

Postby Riccardino » Wed Dec 03, 2008 10:48 pm

[quote="jcompagner"]Web client cant do individual coloring (yet)

Maybe we can improve that in a further version but now we really color the row tag. Then we have to rewrite that
The problem is also then when do you expect to be able to change the colors? All the time? for example when you enter/leave a field? The overhead can be quite large then.
[/quote]

I hoped to replace some unstored calc commonly used for giving a visual feedback for status: e.g. the cell is green if the invoice is payed (or the task has been fixed and so on).

Would this option cause more overhead than a calc? I mean: is an unstored calc returning colored html more efficient than the possible implementation of this feature in rowBgColor?
User avatar
Riccardino
 
Posts: 911
Joined: Thu Apr 24, 2003 11:42 am
Location: Ferrara, Italy

Re: How to use rowBGColorCalc

Postby john.allen » Thu Dec 04, 2008 2:15 am

[quote="jcompagner"]
john: Because in List or Record view we dont really have a event per field, we could have something like that but then the same thing as with the web applies
when do you want to be able to change it? Field enter/leave or really only when a record is set?
[/quote]

The main use I was thinking of was in cases where for different reasons I don't want to set the column restriction to 'not null' but I would like to highlight when the column is in fact null or empty. It would be nice for the datamanagers to be able to easily spot when viewing/updatient/entering a patient record if some particular field was empty. I'm also thinking of perhaps doing something similar in an iPhone application for the MDs. In that case it would be when a returning patient has 'missing data' that the MD needs to be aware of in order to complete on the date of their returning visit. In this case I probably would create a new view in the database containing the relevant columns from the various tables and that could be done in Servoy as a table form. But highlighting the 'missing' column data would still be a problem as on the iPhone I presume it would still be a web client. I'll post this as a feature request also.
john.allen
 
Posts: 515
Joined: Wed Jul 02, 2003 10:07 pm
Location: Stanford CA USA

Re: How to use rowBGColorCalc

Postby jcompagner » Mon Dec 08, 2008 7:06 pm

Riccardino wrote:Would this option cause more overhead than a calc? I mean: is an unstored calc returning colored html more efficient than the possible implementation of this feature in rowBgColor?


yes a calc is just a field and is pretty simple to control and monitor

rowbgcolors requires way more housekeeping becauses it spans over the whole table over all the cells. (we dont know that you only do cell X)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: How to use rowBGColorCalc

Postby schoby » Tue Apr 12, 2011 11:27 pm

Hello,

I am using the rowBGColorCalc method for coloring the fields of a portal. In my case the background color is dependent on many circumstances and I am storing the background colors in an array, but that is not the problem, more or less everything works fine.

The only problem is, that if i change the conditions for the coloring/the contents of the array there is no easy way to trigger the execution of the rowBGColorCalc method.
Of course I can do something like:

elements.portal.setSelectedIndex(i);

which works if element i is not selected before. The point were I run into problems is if the portal just contains 1 element which is selected - there I didn't find any way to trigger the rowBGColorCalc method.

Any idea on this ?

Regards

Schoby
schoby
 
Posts: 26
Joined: Sat Oct 16, 2010 7:14 pm

Re: How to use rowBGColorCalc

Postby jcompagner » Wed Apr 13, 2011 10:15 am

the only way i can quickly think off is that you also show a calc in that portal as a specific field, and when you touch the data you also touch the calc (so the calc also "depends" (touches) that same data)
then the calc will trigger a repaint.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Next

Return to Archive

Who is online

Users browsing this forum: No registered users and 0 guests