gridview

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!

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.

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 …




array(

	'name' => 'Image',

	'type' => 'image',

	'value' => '(!$data->gender ? CHtml::image("neutral.gif") : ($data->gender == "male" ? CHtml::image("male.gif") : CHtml::image("female.gif"))',

	'filter' => '',

),



See this topic. There you will find a css based solution too.

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',

),



no ideia?