Saving GridView filter POST

Hi,

I have the following problem. In my GridView I use POST. I use the Kartik gridview. If I now after data filter are also shown me this. But as soon as I go to page 2 I lose the data. Is there a possibility of Yii the data in the session to be saved? Or do I have to do this by hand?

Thanks for your help

Your Herribert

You’ll have to dig into Pagination to make it work with $_POST.

Similar problem is with Sort - see related issue github.com/yiisoft/yii2/pull/5498

As a simple workaround you may also do something like this (I tried it in search form but I think it can be applied to filters also):




<?php echo GridView::widget([

    ...

    'pager'        => [

           'linkOptions' => [

                'onclick' => 'jQuery(\'#myForm\').prop(\'action\', jQuery(this).prop(\'href\')).submit();'

           ]

    ],

    ...



where #myForm is id of your search form. So its ‘action’ attribute will be substituted by page link when you click it and form will be submitted preserving values of the fields.

You could try the new latest release of the yii2-dynagrid extension. This has been built to save, retrieve and personalize your GridView from the yii2-grid extension.

It allows you to save the grid filters, sorts, pagesize, column order, and grid theme style. You could use a storage type of SESSION, COOKIE, or DB.

Now the intent of this extension is to allow each user to personalize the grid (check the demo). Probably your use case is a bit different… however you could try setting for your use case, the storage to SESSION and attempt configuring the extension for storing the filter data across. Read about the new DynaGridStore object that allows you to fetch, save, and delete data for each dynagrid.

I’m having a similar issue but with the Yii2 GridView.

I’m using an Advanced Search system, and changing page or sorting an attribute from a filtered attributes list gives me incorrect results, as it is not considering my filter inputs.

Any suggestion to fix this?