Simple code to customise the old and ugly default pagination in Yii 2
Customize pagination in views
Todo this trick we need 2 libraries:
Html
and
LinkPager
use yii\helpers\Html; use yii\widgets\LinkPager;
And put the follow in your view
<?= LinkPager::widget(['pagination' => $pagination,'lastPageLabel'=>'LAST','firstPageLabel'=>'FIRST', 'prevPageLabel' => 'Prev', 'nextPageLabel' => 'Next', ]) ?>
Customize pagination in controller
This trick applies for Pagination for
Gridview
I don’t know how your model looks like but because of the
search()
function returns a
dataProvider
, we can change the pagination there:
$searchModel = New\app\models\ServiceChargesSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider->pagination->pageSize=5;
So you don’t need the first instance of dataProvider that you’ve declared before.