Error at GridEdit, conditionally CSS styles

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
strustam
User
Posts: 34
Location: Tajikistan

Error at GridEdit, conditionally CSS styles

Post by strustam »

Hi!

I have project generated by PHPM2020, and there is Row_Rendered() with code for conditionally Change CSS styles of row and cells based on field value. It worked for List/Edit/View/Preview and also for GridEdit
I have error by the same project generated by PHPM2024 at GridEdit, because no $this->myField->CurrentValue

Please advice how to use conditionally Change CSS styles of row and cells based on field value for GridEdit


arbei
User
Posts: 9384

Post by arbei »

You may post your code of Row_Rendered server event for discussion.


strustam
User
Posts: 34
Location: Tajikistan

Post by strustam »

// Row Rendered event
function Row_Rendered() {
	// To view properties of field class, use:
	//var_dump($this-><FieldName>); 
    $this->whenshouldbe->CellAttrs["style"] = "background-color: ";
    $this->status->CellAttrs["style"] = "background-color: ";
    if (!$this->IsGridEdit()) {
	    if ($this->status->CurrentValue == "0") {
		    $dif = date_diff(date_create(date('Y-m-d')),date_create($this->whenshouldbe->CurrentValue));
		    $difsign = (($dif->invert)? - $dif->days : $dif->days);
		    //var_dump($dif);var_dump($this->whenshouldbe->CurrentValue);var_dump(date('Y-m-d'));exit();
		    if ($difsign <= 0) {
			    $this->whenshouldbe->CellAttrs["style"] = "background-color: #ff0000";
			    $this->status->CellAttrs["style"] = "background-color: #ff0000";
		    } elseif ($difsign <= 10) {
			    $this->whenshouldbe->CellAttrs["style"] = "background-color: #ffff00";
			    $this->status->CellAttrs["style"] = "background-color: #ffff00";
		    } elseif ($difsign > 10) {
			    $this->whenshouldbe->CellAttrs["style"] = "background-color: #00ff00";
			    $this->status->CellAttrs["style"] = "background-color: #00ff00";
            }
		}
    }
}

no value at $this->whenshouldbe->CurrentValue


arbei
User
Posts: 9384

Post by arbei »

Note that Row_Rendered is fired for all pages, but there is no value yet in Add page. You should check if $this->whenshouldbe->CurrentValue has value first, e.g.

if ($this->whenshouldbe->CurrentValue) {
    // your code
}

strustam
User
Posts: 34
Location: Tajikistan

Post by strustam »

I put this to code for excluding GridEdit

if (!$this->IsGridEdit()) {

}

I have data at this field whenshouldbe in GridEdit
The question is: How to use data of whenshouldbe at GridEdit for CSS, or may I need to use other event instead of Row_Rendered()


arbei
User
Posts: 9384

Post by arbei »

strustam wrote:

I put this to code for excluding GridEdit

if (!$this->IsGridEdit()) {

}

I have data at this field whenshouldbe in GridEdit
The question is: How to use data of whenshouldbe at GridEdit for CSS?

You excluded Grid-Edit, then how can you format for Grid-Edit?


Post Reply