Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pagination buttons limits in yii2

I need in my gridview pagination there show only 3 elements and then in the button pagination show 3 buttons but the button change dynamically.

example buttons pagination:

[1]-2-3...

click in second element

[2]-3-4...

my code:

public function search($params)
{
    $query = Area::find();

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

Thanks !!

like image 696
Archagy Avatar asked Dec 10 '22 19:12

Archagy


1 Answers

You can do this in gridview with the pager attribute

     <?= GridView::widget([
    'dataProvider' => $dataProvider,
    'summaryOptions' => ['class' =>'dfenx_pagination_summary',],
    'pager' => ['options' => ['class' => 'pagination pull-right']],
    'filterModel' => $searchModel,
    'pager' => [
        'maxButtonCount'=>3,    // Set maximum number of page buttons that can be displayed
        ],
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
      ..........

this are the option available for pager

    'pager' => [
        'options'=>['class'=>'pagination'],   // set clas name used in ui list of pagination
        'prevPageLabel' => 'Previous',   // Set the label for the "previous" page button
        'nextPageLabel' => 'Next',   // Set the label for the "next" page button
        'firstPageLabel'=>'First',   // Set the label for the "first" page button
        'lastPageLabel'=>'Last',    // Set the label for the "last" page button
        'nextPageCssClass'=>'next',    // Set CSS class for the "next" page button
        'prevPageCssClass'=>'prev',    // Set CSS class for the "previous" page button
        'firstPageCssClass'=>'first',    // Set CSS class for the "first" page button
        'lastPageCssClass'=>'last',    // Set CSS class for the "last" page button
        'maxButtonCount'=>10,    // Set maximum number of page buttons that can be displayed
        ],
like image 161
ScaisEdge Avatar answered Dec 28 '22 05:12

ScaisEdge