So... GridView have a top-level folder grid
into framework like helpers
, i18n
, db
, etc.
But information about advanced usage it is hidden in darkness.
Also so many issue arise on the related topic pjax
for similar reason.
How about create a new paragraph in documentation to avoid new similar pjax-not-work-like issue?
example content:
In this controller
action
realization in pjax request can be uses all of 3 models and calc a part of view
'view'
/**
* Displays a single main model and two grid of a child models.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
$model = $this->findModel($id);
return $this->render('view', [
'model' => $model,
'params1' => [
'searchModel' => $searchModel1 = new Model1Search(),
'dataProvider' => $searchModel1->search(ArrayHelper::merge(Yii::$app->request->queryParams, [
$searchModel1->formName() => ['mainModelId' => $model->id],
])),
'context' => $model,
],
'params2' => [
'searchModel' => $searchModel2 = new Model2Search(),
'dataProvider' => $searchModel2->search(ArrayHelper::merge(Yii::$app->request->queryParams, [
$searchModel2->formName() => ['mainModelId' => $model->id],
])),
'context' => $model,
],
]);
}
where view
call render another view _model1-index
and _model2-index
with pjax
+GridView
widgets each
DetailView::widget([
'model' => $model,
'attributes' => [
[
'format' => 'raw',
'label' => Yii::t('part', 'One grid title'),
'value' => function ($model) use ($params1) {
/** @var $this yii\web\View */
return $this->render('_model1-index', [
'context' => $model,
'searchModel' => $params1['searchModel'],
'dataProvider' => $params1['dataProvider'],
]);
}
],
[
'format' => 'raw',
'label' => Yii::t('part', 'Two grid title'),
'value' => function ($model) use ($params2) {
/** @var $this yii\web\View */
return $this->render('_model2-index', [
'context' => $model,
'searchModel' => $params2['searchModel'],
'dataProvider' => $params2['dataProvider'],
]);
}
],
]),
]);
Change controller
action
like in a next example for call only called content
/**
* Displays a single main model and two grid of a child models.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
$model = $this->findModel($id);
$showPart1 = true;
$showPart2 = true;
if (Yii::$app->request->isAjax && isset(Yii::$app->request->queryParams['_pjax'])) {
switch (Yii::$app->request->queryParams['_pjax']) {
case '#p0' :
$showPart1 = true;
$showPart2 = false;
break;
case '#p1' :
$showPart1 = false;
$showPart2 = true;
break;
}
}
if ($showPart1) {
$params1 = [
'searchModel' => $searchModel1 = new Model1Search(),
'dataProvider' => $searchModel1->search(ArrayHelper::merge(Yii::$app->request->queryParams, [
$searchModel1->formName() => ['mainModelId' => $model->id],
])),
'context' => $model,
];
}
if ($showPart2) {
$params2 = [
'searchModel' => $searchModel2 = new Model2Search(),
'dataProvider' => $searchModel2->search(ArrayHelper::merge(Yii::$app->request->queryParams, [
$searchModel2->formName() => ['mainModelId' => $model->id],
])),
'context' => $model,
];
}
if ($showPart1 && !$showPart2) {
//pjax widget call Yii::$app->end();
$this->render('_model1-index', $params1 ?? []);
} elseif (!$showPart1 && $showPart2) {
$this->render('_model2-index', $params2 ?? []);
}
return $this->render('view', [
'model' => $model,
'params1' => $params1 ?? [],
'params2' => $params2 ?? [],
]);
}
IMHO we should first start with a discussion about whether we want to keep supporting PJAX.
PJAX is definitively not going to be a core thing in 2.1
Are you going to replace PJAX with something else or drop the idea entirely?
It's going to move to a separate repo, not being bound to the core, so development can be done by people who are using it and progress does not depend on core team.
@cebe why isn't it part of the core anymore?
@bologer multiple reasons:
So no, we aren't going to document PJAX more than it's documented now and yes, it's a good idea to expand GridView docs with examples.
Most helpful comment
It's going to move to a separate repo, not being bound to the core, so development can be done by people who are using it and progress does not depend on core team.