2015-03-19 21 views
0

gridview如果在頁面的右側,左邊是一些菜單,當點擊頁面2時,它不僅刷新gridview,而且包括左邊部分的所有頁面都丟失 - -a全新的頁面出來幫忙〜點擊yii2 gridview linkpager的頁面跳轉錯誤

有調試截圖: before click after click next page

我的行爲是

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'], 
       ], 
     ], 
]); 
?> 
+0

沒有看到實際的代碼是不可能的。 – arogachev 2015-03-19 03:06:12

+0

已更新,請再次參閱〜thx – aishuishou 2015-03-19 03:30:20

+0

您是否希望在沒有頁面重新加載的情況下在'GridView'中分頁?爲什麼不爲了這些目的而簡單地使用內置的'Pjax'? – arogachev 2015-03-19 03:44:07

回答

0

原因你的問題是,你有沒有阻止HTML鏈接從導演到一個新的頁面,讓您的用戶點擊該鏈接,然後加載與返回的內容的新頁面上服務器;在這種情況下是一個沒有應用佈局的信息頁面。您需要在ajax調用之前添加event.preventDefault()以停止此行爲。

但是,正如@arogachev所說,如果您只是想在沒有頁面刷新的情況下使用分頁,那麼只需使用pjax。這就是pjax的設計目的,

+0

你能給一些代碼嗎? – aishuishou 2015-03-20 03:58:05