Yii2 drop down pagination in GridView

Hi,

I want to make dorpdown pagination in yii2 gridview. I tried this in my GridView, but don’t clear what should the next step I do to do.


<label>

<?=     

    $form->field($model, 'pagesize')

    ->dropDownList(

        ["1"=>"1","10"=>"10","25"=>"25","50"=>"50","100"=>"100"],               

        )->label(''); 

    ?>&nbsp;&nbsp;records per page

</label>

I really need your help guys.

Thank you in advance.

You need to set pagination in your DataProvider:

http://www.yiiframework.com/doc-2.0/yii-data-activedataprovider.html

Pls code example.

What is $model in your code? Is it your SearchModel?

Yes it is search model.

Then you need to modify the search function in your SearchModel to something like this:




    public function search($params)

    {

        $query = YourModel::find();


        $dataProvider = new ActiveDataProvider([

            'query' => $query,

            'pagination' => [

                 'pageSize' => $this->pagesize,

            ],

        ]);


        [...]


        return $dataProvider;

    }



The "pagesize" in your model should be set when posting, and with the above modification the search will consider it.