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.
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});
});
PJAX has timeout
option. If PJAX not obtain AJAX response during this timeout, it will perform full page reload.
Use following JS snippet:
$.pjax.defaults.timeout = false; // For JS use case yor should manual override default timeout.
$.pjax.reload({container: '#pjaxId'});
or more short snippet:
$.pjax.reload('#pjaxId', {timeout : false});
Moreover in my projects I use overrided version of Pjax:
/**
* 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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With