Alternate colors on conditioned components (fields) in a browse list
|Product/Release:||LANSA for the Web|
|Abstract:||How to display alternate foreground and background colors when a field is conditionally embedded into a browse list (i.e. using ONCONDITION).|
|Submitted By:||LANSA Technical Support|
LANSA for the Web provides two graphical variables to define colors on alternate rows in a browse list (i.e. when the function runs from a browser). In this way, the first, third, fifth, etc. lines of the browse list will be displayed in one color and the second, fourth, sixth, etc. lines in another one. The variables that define the default for these colors are: *LW3BLACELLFCOLOR, for the foreground color, and *LW3BLACELLBCOLOR, for the background color. These colors can be customized for specific browselists (please, for more information, refer to the "LANSA for the Web - Editor Guide (Includes Developer's View" guide).
On the other hand, LANSA for the Web allows the conditional display of components (e.g. Page Components) by using the <RDML ONCONDITION> tag. For example, imagine that the DISCOUNT field value should only be displayed if the SPECLT -special client- flag is not blank. The following page component could be used:
The ONCONDITION tag can also be used for a field that belongs to a browse list. However, when the field appears in the browse list, it is not be displayed in the alternate colors. The field is only displayed in the background color.
The following work around programatically "flips" a color-flag field, so it can be used on the Page Component. To implement it, perform the following steps:
- Define a Page Component like:
<FONT COLOR=<RDML MERGE="FCOLOR" >><RDML MERGE="DISCOUNT"></FONT>
FCOLOR would contain the color name, like "green" or "pink".
- On the RDML function:
DEFINE FIELD(#FCOLOR) TYPE(*CHAR) LENGTH(30)
DEFINE FIELD(#ACOLOR) TYPE(*CHAR) LENGTH(30)
DEFINE FIELD(#CCOLOR) TYPE(*CHAR) LENGTH(30)
- At the beginning of the logic of the function, add:
CHANGE FIELD(#CCOLOR) TO(*LW3BLCELLFCOLOR)
CHANGE FIELD(#ACOLOR) TO(*LW3BLACELLFCOLOR)
CCOLOR will have the foreground color (e.g. "green"), while ACOLOR will contain the alternate foreground color (e.g. "pink"). Note that the *LW3BLACELLBCOLOR graphical variable is not being used.
- Add #FCOLOR as a hidden field in the browse list.
- Before each time an entry is added to the browse list, add:
IF COND('#FCOLOR *EQ #ACOLOR')
CHANGE FIELD(#FCOLOR) TO (#CCOLOR)
CHANGE FIELD(#FCOLOR) TO (#ACOLOR)
The above code may also be moved to a subroutine.