How To Keep Filtered Data When Going Back From View.php To Admin.php

Hi everybody,

how can I keep the filtered result in a CGridView when I go to a detailed view page and then go back to the admin view? I did not find anything in the forum, or maybe I just used the wrong questions and keywords. So please give me a hint, a link or even better a howto.

Thanx

you can save your model in user state or session variable

CGridView keep state of page and sort

Dear Friend

Here is one example.

Model:Wage,

Controller:WageController.

WageController.php




public function actionAdmin()

{

	$model=new Wage('search');

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

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

	{

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

	}

	Yii::app()->user->setState('grid',$_GET);//saving all the get parameters into session.


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

			'model'=>$model,

		));

}



views/wage/view.php.

Just append the following in view.php




if(Yii::app()->user->hasState("grid"))

{	

	$grid=Yii::app()->user->getState('grid');		

	$route=array("wage/admin");

	echo CHtml::link("Return to Grid",array_merge($route,$grid));

	Yii::app()->user->setState("grid",null);

}



Now you will exactly land from where you came.

It retains previous sorting and page as well.

The only drawback here is ugly looking url.

I hope I helped a bit.

Regards.