yii通过ajax调用删除后更新bootstrap tdgridview

时间:2014-01-22 11:09:09

标签: jquery ajax yii

我尝试使用模态onlick操作中的ajax调用删除行后更新yii bootstrap gridview;

所以,我没有使用gridview删除按钮,你可以看到;

我实际上使用了e.preventDefault()并打开了一个模态:

$('.delete_modal').on('click', function(e) {
                e.preventDefault();
                $('#myModalConfirmDelete #confirmDelete').data('id', $(this).data('id'));
                $('#myModalConfirmDelete #confirmDelete').data('type_domain_or_url', $(this).data('type_domain_or_url'));
            });

此代码适用于模态onclick事件:

$('#myModalConfirmDelete #confirmDelete').on('click', function() {

                var id = $(this).data('id');
                var type = $(this).data('type_domain_or_url');

                $.ajax({
                    url: url + '/user/' + type + '/delete',
                    data: {'id': id},
                    success: function(data) {
                        $.fn.yiiGridView.update('domain-m-grid');
                        $('#myModalConfirmDelete').modal('hide');
                    },
                    dataType: 'json',
                });

            });

我需要编写其他代码并替换:

$.fn.yiiGridView.update('domain-m-grid');

如果我使用标准的yii gridview删除操作,则此代码将被执行:

/*<![CDATA[*/
jQuery(function($) {
jQuery(document).on('click','#domain-m-grid a.delete',function() {
    if(!confirm('Are you sure you want to delete this item?')) return false;
    var th = this,
        afterDelete = function(){};
    jQuery('#domain-m-grid').yiiGridView('update', {
        type: 'POST',
        url: jQuery(this).attr('href'),
        success: function(data) {
            jQuery('#domain-m-grid').yiiGridView('update');
            afterDelete(th, true, data);
        },
        error: function(XHR) {
            return afterDelete(th, false, XHR);
        }
    });
    return false;
});
jQuery('#domain-m-grid').yiiGridView({'ajaxUpdate':['domain-m-grid'],'ajaxVar':'ajax','pagerClass':'pagination','loadingClass':'grid-view-loading','filterClass':'filters','tableClass':'items table table-striped table-bordered table-condensed','selectableRows':1,'enableHistory':false,'updateSelector':'{page}, {sort}','filterSelector':'{filter}','pageVar':'Domain_page'});
});
/*]]>*/

0 个答案:

没有答案