Search code examples
yiiyii-componentscgridviewcbuttoncolumn

Defining more than one CButtonColumn in CGridView


I have been working with Yii's CGridView and I was wondering if there was any way to separate CButtonColumns, or initiate more than one at a time. So that each Button has a specific column with a specific title.


Solution

  • If i understand correctly your question, you can, just add two arrays and define your template and configuration as following:

    $this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'person-grid',
        'dataProvider'=>$model->search(),
        'filter'=>$model,
        'columns'=>array(
            'id',
            'firstName',
            'lastName',
            'language',
            'hours',
            array(
                'header'=>'View',
                'class'=>'CButtonColumn',
                'template'=>'{view}',
                'buttons'=>array(
                    'view'=>
                        array(
                            'url'=>'Yii::app()->createUrl("person/view", array("id"=>$data->id))',
                        ),
                ),
            ),
            array(
                'header'=>'Update',
                'class'=>'CButtonColumn',
                'template'=>'{update}',
                'buttons'=>array(
                    'update'=>
                        array(
                            'url'=>'Yii::app()->createUrl("person/update", array("id"=>$data->id))',
                        ),
                ),
            )
        ),
    ));