Question

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.

Was it helpful?

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

OTHER TIPS

array(
    'header'=>'View',    
    'class'=>'CButtonColumn',
    'template'=>'{view}'
),
array(
    'header'=>'Update',    
    'class'=>'CButtonColumn',
    'template'=>'{update}'
),
array(
    'header'=>'Delete',    
    'class'=>'CButtonColumn',
    'template'=>'{delete}'
),

... if that was what you meant.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top