Show/Hide Toolbars

Navigation: Using PHPRunner > Page Designer > "View as" settings

PHPrunner32x32     PHPRunner manual

Conditional formatting

Scroll Prev Next More


How to use conditional formatting in PHPRunner projects.

The first example illustrates the profitability of the product line where we have a list of products with their respective monthly profit figures. All positive numbers are displayed in black and all negative in red. Changing the font color of this field based on its value helps the viewer immediately spot the losing products and take necessary actions.


To set the formatting proceed to Visual Editor and double-click on the field you want to format. In our case it is the field "Profitability". Select 'Custom' View As option. Add your code in the custom code editor. If the value of the current field is greater than zero, the font color will be black, otherwise red. Always remember to check the syntax of your code.

if ($value > 0) {  


} else {  



$value="<span style='color: " . $color . "'>" .$value . "</span>";

You can also represent the positive and negative results with images. For example there are the red and green circles were added to highlight the performance of each product. To make this work you will simply need to add two more lines to your custom code. Don't forget to place the actual images in the project folder.

if ($value > 0) {  

$value =$value. ' <img src="green.png" alt="" />';  


} else {  

  $value ='<strong>'.$value. '</strong> <img src="red.png" alt='' />';  



$value="<span style='color: " . $color . "'>" . $value . "</span>";


Now, lets say we want to highlight not only the font color itself but also change the background of the cell to yellow.


Because we are no longer working with just the field values, but with the table structure, we will have to use the events to set the background color.

Proceed to the Events screen in the software and select 'After record processed' event for the list page of the Products table. The code will be similar to the one we used earlier. If the value of the 'Profitability' field is less than zero and will set the background of the cell to yellow. You can refer to the software manual for more examples and code syntax.

if ($data["Profitability"]<0)  


Let’s say you want to take it a step further and highlight the entire row of the losing products.

In the same event you can use the same code for the condition check and only change the code for setting the background of the row. You code should look like this. Once again you can find the exact syntax for this example in the software manual.

if ($data["Profitability"] < 0)  


And if you want to change the background color of all rows regardless of the condition, you can simply comment out the condition in this event:


See also

The video tutorial

How to change row background color

How to change cell background color