点击yii2 gridview linkpager的页面跳转错误
问题描述:
gridview如果在页面的右侧,左边是一些菜单,当点击页面2时,它不仅刷新gridview,而且包括左边部分的所有页面都丢失 - -a全新的页面出来帮忙〜点击yii2 gridview linkpager的页面跳转错误
有调试截图:
我的行为是
public function actionList()
{
$model = new Loan();
$dataProvider = new ActiveDataProvider([
'query' => $model->find(),
'pagination' => [
'pagesize' => '1',
],
]);
return $this->renderPartial('list', ['model' => $model, 'dataProvider' => $dataProvider]);
}
我的看法是:
<?php
use yii\grid\GridView;
use yii\grid\SerialColumn;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\LinkPager;
?>
<?=GridView::widget([
'dataProvider' => $dataProvider,
'layout'=> '{items}{pager}',
'columns' => [
['attribute' =>'loan_type','label'=>'借款类型','options' => ['width' => '80']],
['attribute' =>'amount','label'=>'金额','options' => ['width' => '80']],
['attribute' =>'rate','label'=>'还款利率','options' => ['width' => '80']],
['attribute' =>'fee','label'=>'手续费','options' => ['width' => '80']],
['attribute' =>'status','label'=>'状态','options' => ['width' => '80'] ],
['attribute' =>'comment','label'=>'审核意见','options' => ['width' => '80']],
['attribute' => 'created_at','value' =>function($model){return date('Y-m-d',strtotime($model->created_at));},'label'=>'申请时间','options' => ['width' => '150']],
[
'class' => 'yii\grid\ActionColumn',
'header' => '操作',
'template' => '{audit}',
'buttons' => [
'audit' => function ($url,$model) {
return Html::a('<span id="xxxx" class="glyphicon glyphicon-user"></span>','#',['title'=>'审核',
'onclick'=>"
$.ajax({
type: 'GET',
dataType: 'text',
url: 'http://182.92.4.87:8000/index.php?r=loan/pj', //目标地址
error: function (XMLHttpRequest, textStatus, errorThrown) {alert(XMLHttpRequest.status + ':' + XMLHttpRequest.statusText); },
success: function (page)
{
$('.ucRight').html(page);
}
});
return false;",
]);},
],
'urlCreator' => function ($action, $model, $key, $index) {
return Yii::$app->getUrlManager()->createUrl(['loan/list','id' => $model->status]);
},
'headerOptions' => ['width' => '80'],
],
],
]);
?>
答
原因你的问题是,你有没有阻止HTML链接从导演到一个新的页面,让您的用户点击该链接,然后加载与返回的内容的新页面上服务器;在这种情况下是一个没有应用布局的信息页面。您需要在ajax调用之前添加event.preventDefault()以停止此行为。
但是,正如@arogachev所说,如果您只是想在没有页面刷新的情况下使用分页,那么只需使用pjax。这就是pjax的设计目的,
+0
你能给一些代码吗? – aishuishou 2015-03-20 03:58:05
没有看到实际的代码是不可能的。 – arogachev 2015-03-19 03:06:12
已更新,请再次参阅〜thx – aishuishou 2015-03-19 03:30:20
您是否希望在没有页面重新加载的情况下在'GridView'中分页?为什么不为了这些目的而简单地使用内置的'Pjax'? – arogachev 2015-03-19 03:44:07