Yii1自定义 CGridView 中的操作按钮中 CButtonColumn 选项

Yii可以使用CButtonColumn自定义按钮及列样式。

效果展示 

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'knowledge-auth-list-grid',
    'dataProvider'=>$model->search(),
    //'filter'=>$model,
    'columns'=>array(
        array(
            'name' => 'id',
            'type' => 'raw',
            'value' => 'CHtml::link($data->id, array("knowledgeAuthList/view", "id"=>$data->id))'
        ),
        'auth_name',
        'operator',

        array(
            'name' =>'create_time',
            'headerHtmlOptions'=>array(
                'width'=>'280',
            ),
        ),
        array(
            'header'=>'操作',
            'class'=>'CButtonColumn',
        ),
    ),
)); ?>

//控制操作列按钮展示代码
 array(
      'header'=>'操作',
      'class'=>'CButtonColumn',
      'headerHtmlOptions'=>array(
          'width'=>'80',
      ),
      'template'=>'{view} {update} {delete}', //默认显示的三个按钮,要去掉某个按钮,删除相应项即可
  ),
//增加自定义
自定义一个按钮:
比如添加一个额外的功能按钮'设定',点击可跳转到指定id的设定页。
首先,在template中加入新的标签:'template'=>'{set} {view} {update} {delete}',
然后,定义buttons,加入recharge按钮的定义:

array(
    'header' => '操作',
    'class'=>'CButtonColumn',
    'headerHtmlOptions' => array('width'=>'90'),
    'htmlOptions' => array('align'=>'center'),
    'template'=>'{set} {delete}',
    'buttons'=>array(
        'set' => array(
            'label'=>'设定',
            'imageUrl'=>Yii::app()->request->baseUrl.'/images/set.png',
            'url'=>'Yii::app()->createUrl("auth/set", array("id"=>$data->id))',
        ),
    ),
),

//单个按钮的属性:

'buttonID' => array
(
    'label'=>'...',     //显示为图片的title,鼠标放上去以后显示的文字
    'url'=>'...',       //超链接的地址
    'imageUrl'=>'...',  //按钮的图片src
    'options'=>array(), //按钮的html属性,譬如width,height,style,class等等
    'click'=>'...',     //点击的JS动作,需放在function(){}中
    'visible'=>'...',   //显示该按钮的条件,如 'visible'=>'$data->score > 0',
)

 
//修改删除按钮的提示:

array
(
    'class'=>'CButtonColumn',
    'deleteConfirmation'=>"js:'Record with ID '+$(this).parent().parent().children(':first-child').text()+' will be deleted! Continue?'",
),
原文地址:https://www.cnblogs.com/wt645631686/p/10061729.html