cgridview custom filter

i have a grid with filter

i want add custom filter field, outside the grid

how can i do it?

the problem =if i use grid filter, it don’t include outside filter field

You can use a form like the ‘advanced search’ on the crud admin page:

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

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

	$.fn.yiiGridView.update('your-grid-id', {

		data: $(this).serialize()


	return false;




<div id="search-form" class="wide form">

<?php $form=$this->beginWidget('CActiveForm', array(



)); ?>

	<div class="row">

		<?php echo $form->label($model,'attribute'); ?>

		<?php echo $form->textField($model,'attribute',array('size'=>20,'maxlength'=>20)); ?>


	<div class="row buttons">

		<?php echo CHtml::submitButton('Search'); ?>


<?php $this->endWidget(); ?>


<?php $this->widget('zii.widgets.grid.CGridView', array(






it’s not the same

if i add different field (field than not in grid )to this search form, then make search and then filter in grid, it will resed my custom field value

this form only fill grid filter fields

I see what you mean now. I have a page that does this and I didn’t even realize this issue!

Well, now we both have this problem! Awesome.


Ok friend, I found a workaround for our now-shared issue. Add this to your beforeAjaxUpdate in the CGridView



             var fields = $(\'#search-form form\').serializeArray();

             $.each(fields, function(i, field){

                 if( == "model[attribute1]" || == "model[attribute2]")

                     options.url = options.url+"&" + encodeURIComponent( + "=" + encodeURIComponent(field.value);




thanks, but as for me it’s not beautiful solution

may be there is another solution, when cgridview automatic use custom filter fields, outside the grid?

Does it not work, or is it just not your style?

If you’re using ajax to update, you’re going to have to use some kind of javascript function, or extend CGridView somehow.

Here’s an option without a loop:



            var fields = "&" + encodeURIComponent("model[attribute]") +

                      "=" + encodeURIComponent($(\'#search-form #model_attribute\').val());

            options.url = options.url+fields;





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

             options.url = options.url + "&" + $(".search-form form").serialize();



thanks, this is more good solution

so i see there is no standart yii solution to use custom filter fiels

all thanks