miRRor
(Armand Niculescu)
1
Hey guys,
I’m wondering if you can help me out with this issue:
I’m using Yii2, advanced and I set this in my action:
$dataProvider = new ActiveDataProvider([
'query' => Article::find()
->join("INNER JOIN", "team", "team.team_id = article.team_id")
->where(['team.team_id' => $teams_id]),
'pagination' => [
'pageSize' => 10,
],
]);
return $this->render('listArticles', [
'dataProvider' => $dataProvider,
]);
and I set up the grid, I see all the rows but pagination is not present, even if the rows count is greater than 10.
Thanks in advance for your help,
Armand
miRRor
(Armand Niculescu)
2
I found the fix for that, in the view you have to set the pagination after searchModel:
$searchModel = new ArticleSearch();
$dataProvider = $searchModel->search(Yii::$app->request->get());
$dataProvider->setPagination(['pageSize' => 10]);
this code can be removed from the action
'pagination' => [
'pageSize' => 10,
],
CeBe
3
You should move the searchModel to the action then.
CeBe
4
// action code
$searchModel = new ArticleSearch();
$dataProvider = $searchModel->search(Yii::$app->request->get());
$dataProvider->setPagination(['pageSize' => 10]);
$dataProvider->query->join("INNER JOIN", "team", "team.team_id = article.team_id")
->where(['team.team_id' => $teams_id]);
return $this->render('listArticles', [
'dataProvider' => $dataProvider,
]);
miRRor
(Armand Niculescu)
5
yeah that would be a better way to deal with it, thanks for your comment
actually the correct code would be like this:
$dataProvider = new ActiveDataProvider([
'query' => Article::find()
->join("INNER JOIN", "team", "team.team_id = article.team_id")
->where(['team.team_id' => $teams_id]),
]);
$searchModel = new ArticleSearch();
$dataProvider = $searchModel->search(Yii::$app->request->get());
$dataProvider->setPagination(['pageSize' => 10]);
return $this->render('listArticles', [
'dataProvider' => $dataProvider,
'searchModel' => $searchModel
]);