Gridview Remember Filters, Sorting, Pagination

Hey!

Is there a nice way to save the filtres, sorting and pagination in the GridView?

Has anybody done this before?

Can anybody point me to a tutorial or something?

Resurrecting an old topic since I have crossed this issue recently as well. And I hope that my tips will help someone else today, looking for a similar problem.

Depending on what do you mean by “remembering”?

By default and out-of-the-box Yii 2 gives you a total control over pagination and sorting via URL, i.e.:

/frontend/web/patient/index?per-page=50&sort=created_by&page=3

Since these are part of the request, you can easily intercept per-page, page and sort items and i.e. save them in a cookie (yii\web\Cookie).

Adding filters to that shouldn’t be a problem. I don’t use filters directly (i.e. the mechanism again offered out-of-the-box in GridView), but rather consider encoding them in an URL.

I am still researching, if proposed solution is correct in terms of security and performance. But, if yes, then I could imagine intercepting filter key from the request again, and saving it to a cookie etc.

1 Like