Modifying CGridView's default filter/search behaviour

Hi, I use similar code for external filters but I add after the each:




if($('.filter:not([disabled])', $('#" . $this->getId() . "')).length==0){

	$.fn.yiiGridView.update('". $this->getId() ."', {url:'".Yii::app()->request->requestUri."'});

}else{

	var data=$.param($('.filter:not([disabled])', $('#" . $this->getId() . "')));

	$.fn.yiiGridView.update('". $this->getId() ."', {data: data});

}



I hope it help

I’ve just had a similar problem :

i have a search form for a cgridview containing select inputs with "multiple" option set

when i try to reset the form, the last selected values are still sent

i notice that the serialize is ok, but the url used by the cgridview contains all the form fields, i think because it’s a GET query…

so i did this as a workaround :


<?php

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

$('#search-button').click(function(){

	$('.search-form').toggle();

	return false;

});

$('#init-button').click(function(){

	$(':input','.search-form form')

		.not(':button, :submit, :reset, :hidden')

		.val('')

		.removeAttr('checked')

		.removeAttr('selected'); /* clear all input values */

	$('select option:selected').removeAttr('selected'); /* clear all select values, to be sure ! */

	$('#my-grid').yiiGridView('update', {

		data: '',

		url: '" . Yii::app()->createUrl('controller/action') . "'

	});

	return false;

});

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

	$('#my-grid').yiiGridView('update', {

		data: $(this).serialize()

	});

	return false;

});

");

?>



Just replace the "controller/action", "#my-grid" and "#init-button" with your own settings

i did’nt try in POST instead of GET but it could solve the problem as well…

I am unable to get it to work. I added a reset button to my _search in account model view.


<?php echo CHtml::resetButton('Reset', array('id'=>'form-reset-button')); ?>

To the admin.php file in the account model view, i added the following code:


<?php Yii::app()->clientScript->registerCoreScript('filter-reset',"$('#form-reset-button').click(function()

{

   var id='account-grid';

   var inputSelector='#'+id+' .filters input, '+'#'+id+' .filters select';

   $(inputSelector).each( function(i,o) {

        $(o).val('');

   });

   var data=$.param($(inputSelector));

   $.fn.yiiGridView.update(id, {data: data});

   return false;

});") ?> 



The grid id is account-grid. The reset button just clears the fields but not the filters. What am i doing wrong here?