weina67
(Weinanas)
August 4, 2011, 10:13pm
1
Hello,
I want to use an if condition when using the CGridView to show an image for each row. You see the image shown depends on the $data->gender value. if the person is male, a male picture is shown. If the person is female, a female picture is shown. How can I do that?
For example,
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'yum-messages-grid',
'dataProvider' => $model->search(),
'columns'=>array(
array(
'type' => 'raw',
'name' => 'Image',
'value' => $image
).),
'htmlOptions' => array('class' => 'tableItems')
)
);
So where it says
[b]array(
'type' => 'raw',
'name' => 'Image',
'value' => $image
)[/b]
We want to change the ‘value’ attribute so that the image shown is based on 3 conditions. If the person is male, a male picture is shown. if female, a female picture is shown. If we don’t know the gender, a neutral image is shown.
Thanks!
mbi
(mbi)
August 4, 2011, 10:50pm
2
maybe its better to override CGridColumn->renderDataCellContent in your own GenderImageColumn-class?
You could use something like this:
'value' => '(!$data->gender ? CHtml::image(unknown) : ($data->gender == male ? CHtml::image(male) : CHtml::image(female))'
But, mbi’s solution would be probably be better.
radames
(Radameh)
December 15, 2011, 12:38pm
4
So,
I do like this ,
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'verfpf-grid',
'dataProvider'=>[b]new CArrayDataProvider(Verfpf::getIndexfpf()),[/b]
'columns'=>array(
'ds_cronog',
'nr_verfpf',
'nr_controle',
but, the ID is not here
array(
'class'=>'CButtonColumn',
),
give a help please
tanks …
mpluss
(Mahdi Mastouri)
December 15, 2011, 12:59pm
5
array(
'name' => 'Image',
'type' => 'image',
'value' => '(!$data->gender ? CHtml::image("neutral.gif") : ($data->gender == "male" ? CHtml::image("male.gif") : CHtml::image("female.gif"))',
'filter' => '',
),
joblo
(Joe)
December 15, 2011, 5:32pm
6
See this topic. There you will find a css based solution too.
radames
(Radameh)
December 16, 2011, 1:26pm
7
ok, guys …
it is natural that Framework generates a model like this
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'papel-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'nm_papel',
‘dataProvider’=>$model->search(),
but, in my code is a function …
'dataProvider'=> new CArrayDataProvider(Verfpf::getIndexfpf()),
and I can’t get ID in …
array(
'class'=>'CButtonColumn',
),