2016-09-18 7 views
3

ページ全体を更新せずにpjaxのリストビューをリフレッシュできるようにしたい。これは、pjaxリスト自体のビューです。yii2でpjax listviewを更新するには?ページ全体をリロードする

<?= Html::Button('refresh-countries', ['class' => 'btn btn-primary', 'name' => 'login-button', 'id'=>'refresh']) ?> 

<?php Pjax::begin(['id' => 'countries']) ?> 

    <?= ListView::widget([ 
     'dataProvider' => $dataProvider, 
     'itemOptions' => ['class' => 'comment-item'], 
     'itemView'  => 'commentadapter', 

    ]); ?> 

<?php Pjax::end() ?> 

ボタンをクリックして更新すると、リストビューのみが更新されます。私はそれを行う方法を知っているが、それはページ全体をリフレッシュする。

答えて

0

Pjax:begin()の下にあるボタンを再試してみてください。同じURLに現在のURLを設定します。

<?php Pjax::begin(['id' => 'countries']) ?> 
    <?= Html::a("Refresh Countries", ['Your Current Url to view Country'], ['class' => 'btn btn-lg btn-primary']);?> 
      <?= ListView::widget([ 
       'dataProvider' => $dataProvider, 
       'itemOptions' => ['class' => 'comment-item'], 
       'itemView' => 'commentadapter', 

      ]); 
       ?> 
    <?php Pjax::end() ?> 
+0

デモます。http:私のプロジェクトでさらに

$.pjax.reload('#pjaxId', {timeout : false}); 

私はPjaxのオーバーライドバージョンを使用//blog.neattutorialsを.com/examples/pjax/web/site/index – dungphanxuan

+0

リフレッシュするとページがリフレッシュされません – arinze

+0

pjaxでリストビューを更新します。与えられた例は正しいです。何らかのアクションを要求せずにリフレッシュする方法は他にありません。 – BHoft

2

あなたがこれを好きに持っている:

$("#my_tab_id").click(function() { 
      $.pjax.reload({container: '#some_pjax_id', async: false}); 
     }); 
+0

ありがとうございましたが動作しませんでした。再読み込みや更新はしません – arinze

+0

jqueryで使用しました – arinze

2

PJAXがtimeoutオプションがあります。

ここタブに含まれていると、フォーム上の
use yii\widgets\Pjax; 

<?php Pjax::begin(['id' => 'some_pjax_id']) ?> 
    //your code 
<?php Pjax::end() ?> 

はpjaxリロードする私のスクリプトです。このタイムアウト中にPJAXがAJAXレスポンスを取得しない場合、PJAXはフルページリロードを実行します。 使用以下のJSは、スニペット:

$.pjax.defaults.timeout = false;  // For JS use case yor should manual override default timeout. 
$.pjax.reload({container: '#pjaxId'}); 

以上の短い抜粋:

/** 
* Custom Pjax with incremented timeout. 
* JS for Pjax updating: 
* <code> 
*  $.pjax.defaults.timeout = false;    // For JS use case yor should manual override default timeout. 
*  $.pjax.reload({container: '#pjaxId'}); 
* 
*  // OR 
*  $.pjax.reload('#pjaxId', {timeout : false}); 
* 
*  // OR for gridview with search filters 
*  $('.grid-view').yiiGridView('applyFilter'); // Thats true only if you have search Filters 
* </code> 
* 
* Note: In more cases ID of widget should be static, because widgetId is autoincremented and browser version of page may be not up-to-date. 
*/ 
class Pjax extends \yii\widgets\Pjax 
{ 
    /** 
    * @var int Timeout {@link \yii\widgets\Pjax::$timeout}. 
    *   For JS use case yor should manual override defaults ( $.pjax.defaults.timeout = false; ). 
    */ 
    public $timeout = 30000; 
} 
関連する問題