1.点击事件需要在Pjax::begin() 和Pjax::end()范围内
2.需要在链接配置数组后加上 ['data-pjax'=>'#testPjax'] 其中,'#testPjax‘是页面的id
3.后台Action:return renderAjax('xxx');
test.php
<?php Pjax::begin(['id'=>'testPjax']); echo yii\grid\GridView::widget([ 'dataProvider' => $provider, 'emptyText'=>'can not get anything from server!!!!', 'columns' => [ ['class' => 'yii\grid\CheckboxColumn'], 'name', 'password', ['label'=>'测试新增列->name','value'=>'name'], [ 'class'=>'yii\grid\ActionColumn', 'header'=>'操作', 'template'=>'{view}{delete}{update}', 'buttons'=>[ 'delete'=>function ($url,$model,$key){ return Html::a('<i class="glyphicon glyphicon-trash"></i>', ['del', 'id' => $key], ['data-pjax'=>'#testPjax'], [ //'class' => 'btn btn-default btn-xs', 'data' => ['confirm' => '你确定要删除文章吗?',] ] ); }, ], ], ], ]); Pjax::end(); ?>
后台Action:
public function actionDel($id=null,$name=null) { //echo $id; return $this->renderAjax('show',['data'=>$id]); }
show.php:
<?php //Pjax::begin(['id'=>'testPjax']); if (isset($data)) { echo "<h1>测试Pjax成功! delete id :".$data."</h1>"; } //Pjax::begin(['id'=>'testPjax']); //echo $data; //Pjax::end(); //?>
点击删除后: