beforeAjaxUpdate on delete cgridview yii


beforeAjaxUpdate on delete cgridview yii

这是我的代码

$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'dsfsd',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'cssFile' => false,
    'itemsCssClass' => 'table table-striped',
    'beforeAjaxUpdate'=>'js:function(id,options){$.blockUI({
                            message: "Please wait",
                            //showOverlay: false,
                            css: {
                                border: "none",
                                padding: "15px",
                                "-webkit-border-radius": "10px",
                                "-moz-border-radius": "10px",
                                opacity: 1,
                                "z-index": "9999"
                            }
                        });}',
    'columns' => array(
        array(
            'header' => '#',
            'name' => 'id',
            'type' => 'raw',
            'value' => 'CHtml::link(CHtml::encode($data->id),array("abc/m/".CHtml::encode($data->id)."/info"))',
            'htmlOptions' => array('width' => '40px'),
            'filter' => CHtml::activeTextField($model, 'id', array('placeholder' => 'search by id')),
        ), array(
            'header' => 'First name',
            'name' => '$data.user.f_name',
            'type' => 'raw',
            'value' => 'CHtml::encode($data->user->f_name)',
        ), array(
            'header' => 'Last name',
            'name' => '$data.user.l_name',
            'type' => 'raw',
            'value' => 'CHtml::encode($data->user->l_name)'
        ),
        array(
            'class' => 'CButtonColumn',
            'template' => '{update} {delete}',
            //'updateButtonUrl' => 'Yii::app()->createUrl("abc/xyz?id=".$data->id."&c_id=".$data->c_id)',
            'deleteButtonUrl' => 'Yii::app()->createUrl("xyv/abc",array("uid"=>$data->id))',
        ),
    ),
));

好吧,我想要的是在beforeAjaxUpdate下的操作将只在删除按钮被点击时工作,而不是在搜索或更新上的任何其他ajax操作。这怎么可能?

可以为删除按钮添加回调函数:http://www.yiiframework.com/doc/api/1.1/CButtonColumn buttons-detail

你应该在按钮配置数组中设置click选项:

'columns' => array(    
 ...
 'buttons'=>array(
     'class'=>'CButtonColumn',
     'template'=>'{delete}{update}',
     'buttons'=>array(
         'delete'=>array(
             'click'=>'function(){/*your code here*/}'
         )
     )
  )
  ...
)

可以从回调函数中返回false以防止删除