[EXTENSION] remember-filters-gridview

that did the trick! Nice!!!

First of all: Thanks a lot for this extension!

Regarding pagination:

Saving the pagination is only an issue if the user uses the AJAX version of the grid view, and as far as I can tell it always appends a parameter caleed ajax-[model_name] to the GET request.

So you can differentiate if the user is coming to the page for the first time or if he has clicked on the link for the first page by checking if this parameter is supplied.

You can therefore use the simple version of Jeremys solution (part 4 in post #18):




        // persist page number

        $pageParam = ucfirst($this->modelClass) . '_page';

        //reset pageParam if user clicks on first page.

        if (!isset($_GET[$pageParam]) && isset($_GET['ajax'])){

            $_GET[$pageParam] = 0;

        }

        if (isset($_GET[$pageParam])){

            $page = intval($_GET[$pageParam]);

            Yii::app()->user->setState($this->id . '-page', $page);

        } else {

            $page = Yii::app()->user->getState($this->id . '-page', 1);

            $_GET[$pageParam] = $page;

        }



Tested with yii 1.1.8 and Firefox 6.

HTH

Jak

Hi Pentium10,

Does this extension work on page size also.

Regards,

Praveen J.

Easy solution to the save page and sort issue: modify doReadSave in ERememberFiltersBehavior.php




    private function doReadSave() {

        if ($this->owner->scenario == 'search') {

            $this->owner->unsetAttributes();

            

            // store also sorting order

            $key = get_class($this->owner).'_sort'; 

			if(!empty($_GET[$key])){

				Yii::app()->user->setState($this->getStatePrefix() . 'sort', $_GET[$key]);

			}else {

				$val = Yii::app()->user->getState($this->getStatePrefix() . 'sort');

				if(!empty($val))

					$_GET[$key] = $val; 

			}

			// store active page in page

			$key = get_class($this->owner).'_page';

			if(!empty($_GET[$key])){

				Yii::app()->user->setState($this->getStatePrefix() . 'page', $_GET[$key]);

			}else {

				$val = Yii::app()->user->getState($this->getStatePrefix() . 'page');

				if(!empty($val))

					$_GET[$key] = $val;

			}

			

            if (isset($_GET[get_class($this->owner)])) {

                $this->owner->attributes = $_GET[get_class($this->owner)];

                $this->saveSearchValues();

			} else {

                $this->readSearchValues();

            }

        }

    }



Hi Splainiac,

When i added your code and checked against the grid, i found a issue.

The issue is, example: there are 10 pages in my grid, when i go to 2nd page and then move to view page and come back to the grid it remains on the second page it self, that is working fine, but the link to 1st page is not working once you get back to the grid, can you please verify the same. :)

Thank You,

Praveen J

Hi,

This can be solved by adding this code found in this topic:

private function doReadSave() {

[b] //reset pageParam if user clicks on first page.

     $key1 = get_class($this->owner).'_page';


     if (!isset($_GET[$key1]) && isset($_GET['ajax'])){


           $_GET[$key1] = 1;


     }  [/b] 


                     


   if ($this->owner->scenario == 'search') {

Hi Soter,

Thanks for the help. Sorry if i have done something wrong, below is my code as you suggested, but the first page link is still not working, i am using firefox.

private function doReadSave() {

    //reset pageParam if user clicks on first page.


    $key = get_class($this->owner) . '_page';


    if (!isset($_GET[$key]) && isset($_GET['ajax'])) {


        $_GET[$key] = 0;


    }





    if ($this->owner->scenario == 'search') {


        $this->owner->unsetAttributes();





        // store also sorting order


        $key = get_class($this->owner) . '_sort';


        if (!empty($_GET[$key])) {


            Yii::app()->user->setState($this->getStatePrefix() . 'sort', $_GET[$key]);


        } else {


            $val = Yii::app()->user->getState($this->getStatePrefix() . 'sort');


            if (!empty($val))


                $_GET[$key] = $val;


        }


        // store active page in page


        $key = get_class($this->owner) . '_page';


        if (!empty($_GET[$key])) {


            Yii::app()->user->setState($this->getStatePrefix() . 'page', $_GET[$key]);


        } else {


            $val = Yii::app()->user->getState($this->getStatePrefix() . 'page');


            if (!empty($val))


                $_GET[$key] = $val;


        }





        if (isset($_GET[get_class($this->owner)])) {


            $this->owner->attributes = $_GET[get_class($this->owner)];


            $this->saveSearchValues();


        } else {


            $this->readSearchValues();


        }


    }


}

Regards,

Praveen J

Hi Praveen,

works fine for me on IE7 and Chrome, try to clear cache;

Oh, actually i have

//reset pageParam if user clicks on first page.

     $key1 = get_class($this->owner).'_page';


    if (!isset($_GET[$key1]) && isset($_GET['ajax'])){


           $_GET[$key1] = 1;


     }  

Hi Soter,

Hehe… That works great. Thanks alot for the help :). Sorry if m asking for more just another concern. Do u know any extension or additional code for the same extenson to make it work for page size also. :) :) :)

Hi,

Maybe the user should use filters to refine his search :)

This should work http://www.ramirezcobos.com/2010/11/30/custom-page-size-for-cgridview/

Not tested

If success please post it :D

kind regards,

Soter

Hi Soter,

Hehe… :) i am already using a this extension http://www.yiiframework.com/extension/pagesize for custom grid size. Wanted the remember filters work for that too… ;) :)

Thanks You,

Praveen J.