S
S
sokollondon2018-04-17 07:31:21
Yii
sokollondon, 2018-04-17 07:31:21

Yii2 DataProvider Pagination how to open the last page by default?

'pagination' => [
     'pageSize' => 20,
],

For example, to display comments. To see the latest by default.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sokollondon, 2018-05-03
@sokollondon

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

//Этот код располагать ниже всех операций с $query
if(!Yii::$app->request->get('page')){
    $dataProvider->pagination->page = ceil($dataProvider->getTotalCount() / $dataProvider->pagination->pageSize) - 1;
}

M
Mykola, 2018-04-17
@iSensetivity

'sort' => [
    'defaultOrder' => ['id' => SORT_DESC],
],

M
Maxim Timofeev, 2018-04-17
@webinar

https://www.yiiframework.com/doc/api/2.0/yii-data-...
Compute the last one by offset and count

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question