Cgridview Filters In Sidebar

Hi guys

I have a GridView which is really starting to fill up with filters as the user wants to be able to filter on all sorts of stuff.

Would it be possible to move some of the filters to a sidebar ala ‘column2’? I could then just keep the most important filters in the grid and the rest of them can be moved to the sidebar.

I currently have 10 filters in the GridView and my users want to be able to export filter data for all sorts of different scenarios.

Has anyone had any experience of this?

In case anyone else needs to do something like this, I got it working through the help of this great thread.

I just moved the search form to my own Portlet (which I created for various other uses), fed it the model and everything just works.

It requires a bit of thinking regarding relations, but it’s not a problem really.

So now I have a two column layout with custom filters in the sidebar and filters in the gridview, all of which work in tandem.

Anybody needs to know how to do it, just let me know.

I spoke too soon.

The filtering works fine if I filter first in the sidebar and then in grid.

However if I then add another filter in the sidebar, any filters set in the grid are reset to default.

In my grid I have this which pulls in the data from the sidebar:

'beforeAjaxUpdate' => 'js:function(id, options) {

                             options.url = options.url + "&" + $("#searchForm").serialize();


The search form code is as such:

Yii::app()->clientScript->registerScript('search', "

$('#search-form form').submit(function(){

        $.fn.yiiGridView.update('export-grid', {

                data: $(this).serialize();


        return false;



So this only seems to be resetting the grid and appending the search form data. But can I change that clientScript to look something similar to the beforeAjaxUpdate script so that it doesn’t reset the grid filters? My js is pretty ropey.

For example, lets say there is a column in the grid ‘Year’. By default it shows every year. If I set it to 2014 and hit tab or enter, I get all rows for the year 2014. But if I change a filter in the sidebar, Year gets reset to all years again. I’d like to keep it at 2014.

Any ideas would be greatly appreciated!



May be this idea can help to solve your problem

Hi thanks for replying!

Yes I had come across that extension before but it does a lot of stuff I don’t need.

I did a bit more digging and found the function $.fn.yiiGridView.getUrl.

So in the search form script I’m just appending the url from the grid to the serialised data from the form and it works. Yah! :slight_smile:

Yii::app()->clientScript->registerScript('search', "

$('#search-form form').submit(function(){

        $.fn.yiiGridView.update('export-grid', {

                data: $.fn.yiiGridView.getUrl('export-grid') + '&' + $(this).serialize()


        return false;



Only issue is that you end up with a dirty url with duplicate params. Not a big issue as it’s only noticeable in firebug, but it would be nice to able to somehow merge the params so that the empty duplicate params are parsed out of the url before being returned to the grid.

I’ve done a bit of googling on it and no luck so far. Any ideas on this would be great, but for now it’s working.