Colour in Cell dependant on a value

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
MSB

Colour in Cell dependant on a value

Post by MSB »

Hi All,
In the list a way to change the colour of a cell dependant on its value. I have a table called BOOKINGS with a field called STATUS in it. I would like to change the cell colour as follows when it is Listed.

BOOKINGS.STATUS = New - colour of cell RED
BOOKINGS.STATUS = Pending - colour of cell ORANGE
BOOKINGS.STATUS = Confirmed - colour of cell GREEN

Regards
Martyn


Webmaster
User
Posts: 9425

Post by Webmaster »

Use Row_Rendered server event. Read "Server Events and Client Scripts" in the help file.


MSB

Post by MSB »

Perfect solution Many thanks - here is some code nothing fancy could have used the "Switch" instead of 4 IF's to help anyone who needs this function

// Row Rendered event
function Row_Rendered() {
    // To view properties of field class, use:
    //var_dump($this-><FieldName>);  
    
       if ($this->status->ViewValue=="New") { 
$this->status->CellAttrs["style"] = "color:#FFFFFF; background-color:#FF0000";    
}
    
     if ($this->status->ViewValue=="Confirmed") { 
$this->status->CellAttrs["style"] = "color:#FFFFFF; background-color:#008000";    
}                                             
    
  if ($this->status->ViewValue=="Pending") {         
$this->status->CellAttrs["style"] = "color:#FFFFFF; background-color:#FFA500";    
}   
 
        
          if ($this->status->ViewValue=="Cancelled") { 
$this->status->CellAttrs["style"] = "color:#FFFFFF; background-color:#0000FF";    
}   
  
}

danilo.macri
User
Posts: 93

Post by danilo.macri »

the code works, but I have a problem

if I use a field in the table with a space, it is an error.
how can I do? (I know you that I make a mistake using the spaces)

// Row Rendered event
function Row_Rendered() {
	// To view properties of field class, use:
	//var_dump($this-><FieldName>);

 if ($this->Area Rivervata->ViewValue=="y") { 
$this->Area Riservata->CellAttrs["style"] = "color:#FFFFFF; background-color:#0000FF";
}
}

error:

Parse error: syntax error, unexpected 'Rivervata' (T_STRING) in C:\xampp\htdocs\personale\pc_traduzioniinfo.php on line 1118


mobhar
User
Posts: 11660

Post by mobhar »

You may actually check from the generated code in the related script files. Usually, the space character in a field name will be removed. So, your code above should be:

if ($this->AreaRivervata->ViewValue=="y") {
    $this->AreaRiservata->CellAttrs["style"] = "color:#FFFFFF; background-color:#0000FF";
}

danilo.macri
User
Posts: 93

Post by danilo.macri »

ERROR

Notice: Undefined property: cpc_traduzioni_list::$AreaRivervata in C:\xampp\htdocs\personale\pc_traduzioniinfo.php on line 1118
Notice: Trying to get property 'ViewValue' of non-object in C:\xampp\htdocs\personale\pc_traduzioniinfo.php on line 1118


arbei
User
Posts: 9292

Post by arbei »

The $this->AreaRiservata in your code is null. You better check the generated code to find the correct variable name of the field, or you may see Tools -> Database, Table and Field Variable Names.


mobhar
User
Posts: 11660

Post by mobhar »

If I am not mistaken, this code:

if ($this->AreaRivervata->ViewValue=="y") {
    $this->AreaRiservata->CellAttrs["style"] = "color:#FFFFFF; background-color:#0000FF";
}

will cause an notice error as follows:
Notice: Undefined property: cpc_traduzioni_list::$AreaRivervata in C:\xampp\htdocs\personale\pc_traduzioniinfo.php on line 1118

So, your code above should be:

if ($this->AreaRiservata->ViewValue=="y") { // it should be AreaRiservata instead of AreaRivervata
    $this->AreaRiservata->CellAttrs["style"] = "color:#FFFFFF; background-color:#0000FF";
}

anonga
User
Posts: 3

Post by anonga »

Spaces are replaced by underscores. The code should be:

if ($this->Area_Riservata->ViewValue=="y") { // it should be Area_Riservata instead of AreaRivervata
    $this->Area_Riservata->CellAttrs["style"] = "color:#FFFFFF; background-color:#0000FF";
}

arbei
User
Posts: 9292

Post by arbei »

To check variable names, see Database, Table and Field Variable Names.


Post Reply