Hello, I guess there is a problem with my class extends of CDataColumn. I write this class in order to custom the data cell html options to colored the cell regarding his content. However the problem is that the html option are always applied not for the current row but for the next one and I don’t understand why…
Thus the first row columns are not colored but are in default html option, and the seconde row has his columns colored like the first row should have been, the third row get the second html options etc… all html options are shifted of 1 row :
class MyColoredColumn extends CDataColumn
{
/**
* @var string a PHP expression that will be evaluated for every data cell and whose result will be rendered
* as the URL of the hyperlink of the data cells. In this expression, the variable
* <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;
* and <code>$this</code> the column object.
*/
public $myData;
/**
* @var array the HTML options for the data cell tags.
*/
public $htmlOptions=array();
/**
* Renders the data cell content.
* This method renders a hyperlink in the data cell.
* @param integer $row the row number (zero-based)
* @param mixed $data the data associated with the row
*/
protected function renderDataCellContent($row,$data)
{
$attribute = $this->myData;
if($attribute=='start_time') {
if($data->start_time) {
$this->htmlOptions['class'] = 'green';
}
else {
$this->htmlOptions['class'] = 'yellow';
}
echo $data->start_time ? $data->start_time : "Pending";
}
elseif($attribute=='end_time') {
if($data->end_time)
$this->htmlOptions['class'] = 'green';
elseif($data->start_time and !$data->end_time)
$this->htmlOptions['class'] = 'yellow';
elseif(!$data->end_time and !$data->start_time)
$this->htmlOptions['class'] = 'red';
else
$this->htmlOptions['class'] = 'red';
echo $data->end_time ? $data->end_time :
$data->start_time ? "Ongoing" : "";
}
}
}
...
'columns'=>array(...
array('name'=>'start_time','class'=>'MyColoredColumn','myData'=>'start_time'),
array('name'=>'end_time','class'=>'MyColoredColumn','myData'=>'end_time'),
),
...
can you help ?