Par*_*oft 2 jquery yii cgridview
默认情况下,删除按钮会将自己分配给此功能:
jQuery('#main-orders-details-grid a.delete').live('click',function() {
if(!confirm('Are you sure you want to delete this item?')) return false;
var th=this;
var afterDelete=function(){};
$.fn.yiiGridView.update('main-orders-details-grid', {
type:'POST',
url:$(this).attr('href'),
success:function(data) {
$.fn.yiiGridView.update('main-orders-details-grid');
afterDelete(th,true,data);
},
error:function(XHR) {
return afterDelete(th,false,XHR);
}
});
return false;
});
Run Code Online (Sandbox Code Playgroud)
有没有办法覆盖此功能并添加用户定义的功能?
我遇到了一些嵌套网格的麻烦 - 当我从子网中删除一行时,它会更新主网格.
小智 5
当然可以 :).我假设您已经定义了一个CButtonColumn类列.你可以这样做:
array(
'class'=>'CButtonColumn',
'template'=>'{view}{delete}',
'buttons'=>array(
'view'=>array(
'url'=>'Yii::app()->createUrl("controller/action",array("id"=>$data>id))',
),
'delete'=>array(
'url'=>'#',
'click'=>'js:function(evt){
evt.preventDefault();
/*Your custom JS goes here :) */
}',
),
),
),
Run Code Online (Sandbox Code Playgroud)
另请查看Yii的文档:http://www.yiiframework.com/doc/api/1.1/CButtonColumn#buttons-detail