如何禁用gridview视图按钮或将可见性设置为false

时间:2012-06-22 10:48:34

标签: gridview yii visible cgridview cbuttoncolumn

有些伙伴可以建议如何禁用cgridview小部件上的查看按钮以及如何添加更多按钮,如活动..

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'customer-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
       'id',
       'first_name',
           'last_name',
       'club.club_name',
       array(
         'class' => 'CButtonColumn',
                     'updateButtonUrl' =>'Yii::app()->createUrl("/customer/editmember1",array("id" => $data->primaryKey))',
                     'updateButtonImageUrl'=>Yii::app()->request->baseUrl.'/images/edit.jpg',
                     'deleteButtonUrl' =>'Yii::app()->createUrl("/customer/delete",array("id" => $data->primaryKey))',
                     'deleteButtonImageUrl'=>Yii::app()->request->baseUrl.'/images/delete.jpg', 
                     'viewButton' => array('visiable' => false), 
            ),

              ),   
               )); 

3 个答案:

答案 0 :(得分:16)

使用“template”属性,只显示所需的按钮:

'class' => 'CButtonColumn',
           'template' => '{update}{delete}',
                 'updateButtonUrl' =>'Yii::app()->createUrl("/customer/editmember1",array("id" => $data->primaryKey))',
                 'updateButtonImageUrl'=>Yii::app()->request->baseUrl.'/images/edit.jpg',
                 'deleteButtonUrl' =>'Yii::app()->createUrl("/customer/delete",array("id" => $data->primaryKey))',
                 'deleteButtonImageUrl'=>Yii::app()->request->baseUrl.'/images/delete.jpg', 
        ),

答案 1 :(得分:3)

这很简单。例如,我有以下网格,我已禁用更新和删除按钮。只有视图按钮具有visible => true

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'activity-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
    'id',
    'employee_id',
    'vehicle_id',
    'radio_id',
    'aed_id',
    'laptop_id',
    /*
    'checked_out_on',
    'checked_in_on',
    */
    array(
        'class'=>'CButtonColumn',
        'template'=>'{update}{view}{delete}',
                    'buttons'=>array(
                    'update'=>array(
                            'visible'=>'false',
                    ),
                    'view'=>array(
                            'visible'=>'true',
                    ),
                    'delete'=>array(
                            'visible'=>'false',
    ),

),

    ),
),

));

$this->widget('zii.widgets.grid.CGridView', array( 'id'=>'activity-grid', 'dataProvider'=>$model->search(), 'filter'=>$model, 'columns'=>array( 'id', 'employee_id', 'vehicle_id', 'radio_id', 'aed_id', 'laptop_id', /* 'checked_out_on', 'checked_in_on', */ array( 'class'=>'CButtonColumn', 'template'=>'{update}{view}{delete}', 'buttons'=>array( 'update'=>array( 'visible'=>'false', ), 'view'=>array( 'visible'=>'true', ), 'delete'=>array( 'visible'=>'false', ),

答案 2 :(得分:2)

        'class' => 'CButtonColumn',
                    'template' => '{update}',
                     'updateButtonUrl' =>'Yii::app()->createUrl("/post/update",array("id" => $data->primaryKey))',
                    'updateButtonImageUrl'=>Yii::app()->request->baseUrl.'/assets/aed78a8d/gridview/update.png',