Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How modify Yii2 pagination in GridView widget to show first and last pages?

Default view of pagination is "1, 2, 3, ..., 10"

I need to transform it into "(first page), x, x, x, (current page), x, x, x, (last page)"

How can I do that?

like image 942
Gorini4 Avatar asked Jan 24 '15 18:01

Gorini4


2 Answers

<?= GridView::widget([
    'pager' => [
        'firstPageLabel' => 'First',
        'lastPageLabel'  => 'Last'
    ],
    ...
]) ?>
like image 60
Liz Avatar answered Nov 19 '22 23:11

Liz


You need to specify $firstPageLabel and $lastPageLabel properties of LinkPager (they are false by default meaning these links are not shown) . You can pass it to GridView like that:

<?= GridView::widget([
    ...
    'pager' => [
        'firstPageLabel' => 'First',
        'lastPageLabel' => 'Last',
    ],
    ...
]) ?>

For styling there are two additional properties: $firstPageCssClass and $lastPageCssClass.

Note that you can apply this to LinkPager separately, without using GridView.

like image 23
arogachev Avatar answered Nov 19 '22 23:11

arogachev