0

My pagination does not show on my index page.

Can someone tell me how to create pagination for my index page with a limit of 15?

public function actionIndex()
{
    $searchModel = new EmployeeSearch();
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
    $pagination = new Pagination([
        'defaultPageSize' => 5,
        'totalCount' =>$this->count(),
    ]);
      $employee = $query->orderBy('name')
        ->offset($pagination->offset)
        ->limit($pagination->limit)
        ->all();

    return $this->render('index', [
        'searchModel' => $searchModel,
        'dataProvider' => $dataProvider,
        'Employee-create' => $employee,
        'pagination' => $pagination,
    ]);
}
Pedro del Sol
  • 2,840
  • 9
  • 39
  • 52

2 Answers2

0

You can set pageSize for data provider this way

$searchModel = new EmployeeSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

$dataProvider->pagination->pageSize=15;
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
0

In you file EmployeeSearch.php include the param pagination

$dataProvider = new ActiveDataProvider([
        'query' => $query,
        'pagination' => [
                'pageSize' => 15,
            ],
]);