Page 1 of 1

Colour in Cell dependant on a value

Posted: Mon Mar 05, 2012 5:04 am
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


Re: Colour in Cell dependant on a value

Posted: Mon Mar 05, 2012 9:30 am
by Webmaster

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


Re: Colour in Cell dependant on a value

Posted: Mon Mar 05, 2012 7:44 pm
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";    
}   
  
}

Re: Colour in Cell dependant on a value

Posted: Wed Aug 25, 2021 10:23 pm
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


Re: Colour in Cell dependant on a value

Posted: Thu Aug 26, 2021 8:06 am
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";
}

Re: Colour in Cell dependant on a value

Posted: Thu Aug 26, 2021 2:07 pm
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


Re: Colour in Cell dependant on a value

Posted: Thu Aug 26, 2021 9:56 pm
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.


Re: Colour in Cell dependant on a value

Posted: Sat Aug 28, 2021 9:41 am
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";
}

Re: Colour in Cell dependant on a value

Posted: Sun Mar 05, 2023 3:35 am
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";
}

Re: Colour in Cell dependant on a value

Posted: Sun Mar 05, 2023 9:46 am
by arbei

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