How modify Yii2 pagination in GridView widget to show first and last pages?
If you are using Bootstrap 4.x.x
'container' => [
'definitions' => [
\yii\widgets\LinkPager::class => \yii\bootstrap4\LinkPager::class,
'yii\bootstrap4\LinkPager' => [
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last'
]
],
],
Note since Yii2 version 2.0.11, you can set firstPageLabel
and lastPageLabel
defaults for the whole application using container definitions in your config/main.php file:
$config = [
....
'container' => [
'definitions' => [
'yii\widgets\LinkPager' => [
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last'
]
]
]
];
Learn more at http://www.yiiframework.com/doc-2.0/guide-concept-configurations.html#application-configurations
<?= GridView::widget([
'pager' => [
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last'
],
...
]) ?>
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
.