How to refresh pjax listview in yii2? It reloads the entire page

arinze picture arinze · Sep 19, 2016 · Viewed 14.6k times · Source

I want to be able to refresh a pjax listview without refreshing the whole page. This is the view just the pjax list itself.

<?= 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() ?>

Please I want it to refresh onclick of that button and only the listview would refresh. I know how to do it but it refreshes the whole page.

Answer

Rahul Pawar picture Rahul Pawar · Sep 19, 2016

You have to like this:

 use yii\widgets\Pjax;

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

above form contained in tab and here is my script to reload pjax :

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