CGridView Filter on Page Load

I have set a value in one of my cgridview filter fields using:

.val($_GET[‘value’]);

The value appears in the search field, but I am unable to trigger the cgridview to refresh or filter. Does anyone know who to trigger the cgridview to filter after page load with a predefined value?

Any help would be greatly appreciated and please let me know if you need additional information.

Thank you

Can you set the value in the controller before rendering the view?

Just figured this out. Not sure if this is exactly what you’re trying to do.

You’ll notice that in the default ‘admin’ action created by gii, there’s a line stating that if the $_GET values are set, use them as the attributes for the search function:




public function actionAdmin()

	{

		$model=new User('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['User']))

			$model->attributes=$_GET['User'];


		$this->render('admin',array(

			'model'=>$model,

		));

	}



I needed to be able to have a link to a pre-filtered cgridview of users. Here’s url that worked for me:


www.<my site name>.com?r=user/admin&User%5Bsite_id%5D=336

And here’s the link in my view file:


array('label'=>'User Operations', 'url'=>array('user/admin', 'User[site_id]'=>$model->id)),

Hope this helps.