zitter, on 06 May 2010 - 09:41 AM, said:
Is it possible to display more values in a table cell, using CGridView? For example something like that, in HTML:
<strong>Name Surname</strong>
<br />
<strong>Groups: </strong> Group1, Group2, Group3, etc.
Where 'name', 'surname' and 'groupN' are data taken from model; in this example could be $User->name, $User->surname, $User-groups (joined with N:M relationship).
TIA
Danilo
Something like this should work for singular properties of the model:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
array(
'name'=>'column_name',
'type'=>'raw',//this line is vital to have html not show up as text
'value'=>'"<strong>".$data->name . " " . $data.surname . "</strong>"',
),
),
));
I'm not sure if this would be the best solution, but to get the group names into a list you could create a function in the model. Here's a rough example.
//model class
public function getGroupNames(){
$groups = '';
foreach($this->groups as $group)
$groups .= $group->name . ' ';
return $groups;
}
//CGridView
'type'=>'raw',
'value'=>'"<strong>" . $data->name . " " . $data->surname . "</strong><br/><strong>Groups:</strong> " . $data->getGroupNames()',