2

默认情况下,删除按钮将自己分配给此功能:

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;
});

有没有办法覆盖这个函数并添加一个用户定义的?

我在使用一些嵌套网格时遇到了一些问题 - 当我从子网格中删除一行时,它会更新主网格。

4

1 回答 1

5

Of course you can :). I assume that you already have a CButtonColumn class column defined. You can do it like so:

        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 :) */
                        }',                        
                ),                    
            ),
        ),

Also check out Yii's doc here: http://www.yiiframework.com/doc/api/1.1/CButtonColumn#buttons-detail

于 2012-05-11T07:00:07.993 回答