You are viewing revision #7 of this wiki article.
This is the latest version of this article.
You may want to see the changes made in this revision.
Clearing CGridView filters and sort orders from the web pages, is usefull for the end user. Yii does not seem to propose a standard method. Furthermore, this is especially usefull when filters are "remembered" in the user's session.
To remember filters, I use ERememberFiltersBehavior and a previous wiki also shows a method to remember filters.
They did not meet my "requirements", so I worked out another method.
The code is not perfect yet (I would like to not use 'window.location.href'), but I thought sharing this is usefull for you. If you work out a better way, share it here!
The code basically goes like this:
This seems less complex and more flexible than the other code I have seen. It also uses the actual sortVar and pageVar values (rather than supposing that they use the Model class name).
By setting the 'clearFilter' class on the 'filter' area of the CButtonColumn, you can suggest the clear filter function by attaching a background to it in your CSS.