Coloring field backgrounds based on values, in list view

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Coloring field backgrounds based on values, in list view

Postby JerryR » Tue Sep 07, 2004 8:51 am

How can you affect the background color of a field, based on that field's value, in a list or table view?
Jerry Robinson
JPR Engineering Inc
JerryR
 
Posts: 104
Joined: Sat Jan 17, 2004 4:30 am
Location: Pacific Palisades, CA

Postby IT2Be » Tue Sep 07, 2004 9:05 am

When you name the element your value is shown in, all accessible properties are shown in the methodeditor. One of them is bgcolor.

By creating a method onShow and onRecordSelect of the form that looks like below you can archieve what you want. Another way is creating a calculated field with html in there.
Code: Select all
if (value == 1) {
  elements.value.bgcolor = 'ffffff';
} else {
  elements.value.bgcolor = 'aaaaaa';
}
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Postby JerryR » Wed Sep 08, 2004 12:52 am

Marcel.. (first off, thank you for the reply!) I understand how what you suggested would work for detail view. I need to do this in a tabless tabpanel displaying a form in table view. Since, in table view, the 'text' property of the form refers to the column header and not the field itself, where would you put the html? And since the data is displaying in a tabless tabpanel on another layout, it's always visible, thus you can't use OnShow, OnHide, or OnRecordSelection (the last because the field color needs to show for all displayed records, not just the one selected). What am I missing?
Jerry Robinson
JPR Engineering Inc
JerryR
 
Posts: 104
Joined: Sat Jan 17, 2004 4:30 am
Location: Pacific Palisades, CA

Postby david » Wed Sep 08, 2004 4:11 am

Check out this thread:

http://forum.servoy.com/viewtopic.php?t=2071

- David
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Postby JerryR » Wed Sep 08, 2004 4:16 am

David... I need to change colors for individual *field* backgrounds, not for the entire row. Still not seeing how to do that.
Jerry Robinson
JPR Engineering Inc
JerryR
 
Posts: 104
Joined: Sat Jan 17, 2004 4:30 am
Location: Pacific Palisades, CA

Postby david » Wed Sep 08, 2004 4:28 am

JerryR wrote:David... I need to change colors for individual *field* backgrounds, not for the entire row. Still not seeing how to do that.


Tough to do in list or table view. Why? A named element is not unique in list or table view. A specific row isM-^Wwhich is why you can color certain rows depending on a value.

Here is where you want to use html to display your data set. This technique requires you to use the "getDataSetByQuery()" method, and then loop through the results building an html table. As you loop and build, you can color any particular background cells based on any conditions you want. In addition, you can attach javascript calls to methods in your html allowing your result to be an html table with the exact formatting you want and with links to manipulate the data further (like go to a detail view for the clicked record).

- David
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 32 guests