我对Yii 2分页有问题。我的情况有点奇怪。我正在尝试做的是在其中包含一些ChartJS的ListView。问题是,当我单击页面按钮时,整个页面将重新加载。 ListView在手风琴组件中,也许这是我无法解决的问题。这是我的代码:
在SiteController中:
$usercenters = Yii::$app->mycomponent->getCenIds();
$query = new Query;
$query->select('distinct(center.id)')
->from('campaign_center')
->innerjoin('center', 'center.id = campaign_center.center_id')
->where("campaign_center.campaign_id = " . $_POST['campaignid'])
->andWhere("campaign_center.center_id in(" . $usercenters . ")");
$centers = $query->all();
$page = $_POST['page'];
$provider = new ArrayDataProvider([
'allModels' => $centers,
'pagination' => [
'pageSize' => 3,
'page' => $page,
'totalCount' => $query->count()
],
'sort' => [
'attributes' => ['id'],
],
]);
return $this->renderAjax('_campaigntypeslevel_list', ['tipojerarquia' => $_POST['tipojerarquia'], 'origincampaigntype' => $_POST['origincampaigntype'], 'campaignid' => $_POST['campaignid'],'provider'=>$provider, 'centers'=>$centers,'usercenters'=>$usercenters]);
第一视图(_campaigntypeslevel_list):
Pjax::begin(['timeout' => 10000, 'clientOptions' => ['container' => 'pjax-container']]);
echo ListView::widget([
'id'=>'centerslistview',
'dataProvider' => $provider,
'layout' => '<div>{summary}</div><div>{pager}</div><div>{items}</div>',
'itemView' =>'_centers',
'viewParams' => ['tipojerarquia' => $tipojerarquia,
'center' => $centermodel->id, 'campaign' => $campaignid,
'origincampaigntype' => $origincampaigntype, 'dataPie' =>
$dataPie, 'dataBox' => $dataBox, '$dataPieLastYear' =>
$dataPieLastYear, 'dataBoxLastYear'=>$dataBoxLastYear,'centers'=>$centers,'usercenters'=>$usercenters],
]);
Pjax::end();
最后在_centers视图中:
<?php
use app\models\Campaign;
use app\models\Center;
$campaignmodel = Campaign::findOne($campaign);
$dataPie = Yii::$app->chartfunctions->getHomeNPSData(Yii::$app->user->identity, NULL, $model['id'], NULL, $campaignmodel->id, NULL, NULL);
$dataBox = Yii::$app->chartfunctions->getHomeNPSDataByMonth(Yii::$app->user->identity, NULL, $model['id'], NULL, $campaignmodel->id, NULL, NULL);
$dataPieLastYear = Yii::$app->chartfunctions->getHomeNPSData(Yii::$app->user->identity, NULL, $model['id'], NULL, $campaignmodel->id, NULL, date('Y'));
$dataBoxLastYear = Yii::$app->chartfunctions->getHomeNPSDataByMonth(Yii::$app->user->identity, NULL, $model['id'], NULL, $campaignmodel->id, NULL, date('Y'));
echo \Yii::$app->controller->renderPartial('_boxcontent', ['tipojerarquia' => $tipojerarquia, 'center' => $model['id'], 'campaign' => $campaignmodel->id, 'origincampaigntype' => $origincampaigntype, 'dataPie' => $dataPie, 'dataBox' => $dataBox, '$dataPieLastYear' => $dataPieLastYear, 'dataBoxLastYear' => $dataBoxLastYear],false,true);
?>
也许渲染不正确?
答案 0 :(得分:0)
问题出在睡衣上。
PJAX具有超时选项。如果在此期间PJAX未获得AJAX响应 超时,它将执行整页重新加载。
检查此问题的答案,同样的问题,也许您会找到答案:
How to refresh pjax listview in yii2? It reloads the entire page