晦涩de咚 2016-03-02 13:56:34 4112次浏览 1条评论 1 0 0

视图文件

$csrfTokenName = Yii::app()->request->csrfTokenName;
$csrfToken = Yii::app()->request->csrfToken;
$csrf = "\n\t\tdata:{ '$csrfTokenName':'$csrfToken' },";
$Confirmation= CJavaScript::encode("js:'你确定要删除:'+$(this).parent().parent().children(':nth-child(2)').text()+'?'"); //提示的内容。
$afterDelete = 'function(){}';
$click=<<<EOD
function() {
var th=this;
var url=$(this).attr('href');
sweetAlert({
    title: "Are you sure?",
    text: $Confirmation,
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "Yes, delete it!",
    closeOnConfirm: false,
    closeOnCancel: false
    }, function(isConfirm){
        if(isConfirm)
        {
            var afterDelete=$afterDelete;
            $.fn.yiiGridView.update('store-type-grid', {
                type:'POST',
                url:url,$csrf
                success:function(data) {
                    $.fn.yiiGridView.update('store-type-grid');
                    afterDelete(th,true,data);
                    swal("Deleted!", "您的文件已被删除.", "success");
                },
                error:function(XHR) {
                   return afterDelete(th,false,XHR);
                }
            });
        }else{
              swal("Cancelled", "本次操作被取消,您的文件安全存在 .", "error");
        }
    });
    return false;
}
EOD;

//CGridView

array(
    'header'=>'操作',
    'class'=>'CButtonColumn',
    'template'=>'{update} {delete}',
    'buttons'=>array(
        'update'=>array(
            'label'=>'修改',
        ),
        'delete'=>array(
            'label'=>'删除',
            'click'=>$click   //事件
        ),
    ),
),
您需要登录后才可以评论。登录 | 立即注册