2017-03-27 11:15:46 0 评论 Yii 2.0 Boy.Lee

Yii 2.0 使用Ajax操作Gridview数据表格

[
    'class' => 'yii\grid\ActionColumn',
    'header'=>'操作',
    'template'=>'{view} {upDown}',
    'buttons'=>[
        'upDown' => function ($url, $model, $key) {
            $label = '显示';
            if ($model->uc_actived == CommonConst::COMSTATUS_YES) {
                $label = '隐藏';
            }
            return Html::a("[$label]", ['#'], ['title'=>$label, 'onclick'=>"
                    var that = $(this);
                    
                    $.ajax({
                        type     :'GET',
                        cache    : false,
                        url  : 'set-up',
                        data  : {id: {$model->uc_id}},
                        success  : function(response) {
                            // 改变Html文字内容
                            if(that.html() == '[显示]'){
                                that.html('[隐藏]')
                            }else{
                                that.html('[显示]')
                            }
                        }
                   })
    
                    // 取消Html link事件响应
                    return false;
    
            "]);
        },
    ]
],