2016-12-16 56 views
0

我有,我會使用pjax喜歡使用分頁列表視圖但pagnation失敗pjax工作yii2 pjax在分頁失敗

這是我曾嘗試

<?php Pjax::begin([ 
       'id' => 'w0', //checked id on the inspect element 

       'enablePushState' => true // i would like the browser to change link 
      ]); ?> 

<?= ListView::widget([ 
       'summary' => false, 
       'dataProvider' => $dataProvider, 
       'emptyText' => "",//Yii::t('app', 'Sorry we have no items currently.'), 
       'itemOptions' => ['class' => 'item'], 
       'options' => ['data-pjax' => true ], //this is for pjax 
       'layout' => '{items}{pager}', 
       'pager' => [ 
        'firstPageLabel' => 'First', 
        'lastPageLabel' => 'Last', 
        'maxButtonCount' => 5, 
        'options' => [ 
         'class' => 'pagination col-xs-12' 
        ] 
       ], 
     'itemView' => function ($model, $key, $index, $widget) { 

     return $this->render('_items_list', ['model' => $model]); //This shows one model 
       }, 
      ]) ?> 

<?php Pjax::end(); ?> 

當我點擊這些項目什麼都沒有兜帽,當我刪除pjax打開和關閉標籤,它與正常頁面刷新一起工作還有什麼我需要添加

回答

1

你接近你的解決方案。

<?php Pjax::begin([ 
    'id' => 'w0', // checked id on the inspect element 
    'enablePushState' => true // I would like the browser to change link 
    'timeout' => 10000 // Timeout needed 
]); ?> 

我已經添加了1行:0​​。默認timeout等於1000(一秒)。由於您在1秒內沒有收到結果,因此瀏覽器使用普通頁面刷新而不是Pjax。通過將1000替換爲10000,您可以給予10倍的時間來獲得迴應(應該不會很長,但以防萬一)。現在,Pjax已經足夠從服務器檢索結果並更新ListView而無需重新加載頁面。

如果你仍然沒有得到任何東西,它可能是服務器端的錯誤。檢查網絡(在瀏覽器中)以查看哪些服務器返回(應該返回狀態200)。