Back
colorLens
Table Cell formating
colorLens
Dynamicly change color of column or cell, and column attributes too.
Default:
You can use this property to enter a grid background color such as 'white' or 'black', or use the numeric RGB values where #000000 and #FFFFFF is white.

To set dynamic colors in your columns, set the first character to an equals (=), then you can use the PHP's ternary logical operator or your own pre-defined function to perform checks and comparisons.

PHP has a nice way of allowing you to choose between multiple values in one line of code:
= (expr) ?
"value if expr is true" : "value if expr is false"



An example is given a column named UnitsInStock, and we want to color the column red if the units are less than 10:
=({UnitsInStock} < 10)? "red" : ""

You can also use any global variables defined in the $GLOBALS array using {$VARNAME}, for example {$PHP_SELF}.

The colorLens property can access any column in the current row using the {columnname} syntax just like the powerLens.

Additional Macro Variables Available
{NBSP} = ' '
{SEMICOLON} = ';'
{_HILITE_RECNO_} = current record number
{_LENSID_} = the phpLens object's id
{_ODDC_} = the odd row color
{_EVENC_} = the even row color
{_SELECTC_} = the hilite color for the current line
{_HASDETAILS_} = whether the detail grid is visible

Changing Column Attributes

You can also change column widths with this property by taking advantage of a side-effect. Any attribute can be added to the TD tag using colorLens. See example in syntax. Note that setting the column width is discretionary. The browser can override this setting if it wants to.

However since phpLens 2.6, we have the tdLens property, which allows you direct access to all td attributes. Note however that tdLens does not do column interpolation (eg {col1}) nor php code processing (with =).

Title and Input Background Colors

Since phpLens 4.9, you can control the background color of the detail, edit and new titles, and the input background colors. To set the title background color for field FIELD1 to black, the title font to white, and the input background to lightyellow, use

$lens->colorLens = 'field1^^black style='color:white'^lightyellow';

To set the grid cell color to pink too, use

$lens->colorLens = 'field1^pink^black style='color:white'^lightyellow';

For title and input cells, the dynamic colors using the = prefix is NOT available.

Syntax
$lens->colorLens = 'totals^yellow'; // color the totals column yellow

$lens->colorLens = 'totals^yellow width=200px'; // ... sets the width too


$lens->colorLens = 'totals^yellow;name^#0000FF'; // and name is blue

 Basic:Yes  Advanced/Enterprise:Yes  DynamicEdit:Yes   [Version 1.0]