How to disable cgridview view button or setting visiability to false

12,883

Solution 1

Use the 'template' property do show only your desired buttons:

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

Solution 2

It is pretty simple. For example I have the following grid where I have disabled the Update and Delete buttons. Only the view button is has 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',
    ),

),

    ),
),

));

Solution 3

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

Coder

Application Programmer, Technologies working on Cakephp, Yii, jQuery, jQuery Mobile, java swings, Android

Updated on June 05, 2022

Comments

  • Coder
    Coder almost 2 years

    can some buddy please suggest how to disable view button on cgridview widget and how to add more button like active..

    $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), 
                ),
    
                  ),   
                   )); 
    
  • Coder
    Coder almost 12 years
    Thanks "sucotronic" it works very well, i am new to yii so having some difficulties thanks again.
  • sucotronic
    sucotronic almost 12 years
    @Coder you're welcome. Yii is a greatly documented and have nice tutorial to start with it. Hope you enjoy as much as me and build great webpages :)
  • Nanhe Kumar
    Nanhe Kumar about 11 years
    Note : aed78a8d this value may be different
  • Nanhe Kumar
    Nanhe Kumar about 11 years
    array( 'class'=>'CButtonColumn', 'template' => '{update} {delete}', ),
  • ChaseHardin
    ChaseHardin about 9 years
    Thanks @sucotronic this was so helpful!