Adding a check box or other button to a CGridView

I know it is possible to add a check box to each row of the CGridView, but is I possible to add some logic based on the data provider to each line.

(i.e. if the contents of one of the columns on a given row is 0 add a check box, and if the value is 1 add a hyperlink.)

Here is my code:




$dataProvider=new CActiveDataProvider('data_products', array('criteria'=>array('condition'=>'dataRequestType=0') ) );


$this->widget('zii.widgets.grid.CGridView', array(

    'dataProvider'=>$dataProvider,

    'columns'=>array(

        'program_name',

        'mediaCount',

        'mediaType',

        'productName',

        'dataRestrictions',

        array(

                'name'=>'',

                'value'=>'CHtml::checkBox("cid[]",null,array("value"=>$data->productName,"id"=>$data->productName))',

                'type'=>'raw',

                'htmlOptions'=>array('width'=>5),

        ),


    ),

));



Would I just add an if statement ‘columns’ array or is there some other logic I’m missing.

Thanks

I suggest you try something like this




...

'value' =>'$data->some_attribute ? CHtml::link(...) : CHtml::checkBox(...)',

...



(not tested)

/Tommy

Thanks a lot that work perfectly.