CGridView column value as dropdown list, achieved from model

Hello, everybody.

I wanna make some CGridView table in a view. And one column should contain DropDown list. Main problem is, that this dropdown list must be generated by model.

So, in my view i made it like this:


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

                'dataProvider'=>$orders->search(),

                'filter' => $orders,

                'columns' => array(

                    array(

                        'name' => 'actions',

                        'header' => 'Actions',

                        'value' => '$data->actions',

                        'filter' => false,




    ),

));

And in Order model:


public function getActions() {

    return CHtml::dropDownList('status', $this->status->id,  CHtml::listData(Status::model()->findAll(), 'id', 'title'));

}

And i getting pretty nice column value with code of this dropdown list, but all special chracters encoded to lt; quot; gt; etc. Just string, not html element.

So, how to get real html dropdown list?

Check the type attribute - http://www.yiiframework.com/doc/api/1.1/CDataColumn#type-detail

Thanks a lot. Of course ‘type’ => ‘raw’ helped.

hi buddy,

I use similar way to create the dropdownlist from model. The problem i am facing now is ajax of those dropdownlist only fires in the first page of the gridview.

Take the Ajax code generated by Yii and register it again in your afterAjaxUpdate property

http://www.yiiframework.com/doc/api/1.1/CGridView#afterAjaxUpdate-detail

Thanks Bennouna. It solved my problem.