【问题标题】:yii2 pjax in the listview fails in pagination列表视图中的 yii2 pjax 分页失败
【发布时间】:2017-05-02 15:31:39
【问题描述】:

我有一个列表视图,我想使用 pjax 进行分页,但分页无法与 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 打开和关闭标签时,它适用于正常的页面刷新我还需要添加什么

【问题讨论】:

    标签: php pagination yii2


    【解决方案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 行:'timeout' =&gt; 10000。默认情况下,timeout 等于 1000(一秒)。由于您没有在那 1 秒内返回结果,因此浏览器使用正常的页面刷新而不是 Pjax。通过将 1000 替换为 10000,您可以多出 10 倍的时间来获得响应(不应该花那么长时间,但以防万一)。现在 Pjax 有足够的能力从服务器检索结果并更新 ListView 而无需重新加载页面。

    如果你仍然没有得到任何东西,很可能是服务器端的错误。检查网络(在浏览器中)以查看服务器返回的内容(它应该返回状态 200)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多