Yii Framework Forum: [EXTENSION] remember-filters-gridview - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

[EXTENSION] remember-filters-gridview This extensions helps you to remember/store filter values of GridViews Rate Topic: -----

#21 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 18 July 2011 - 12:37 PM

that did the trick! Nice!!!
0

#22 User is offline   jak 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 21-October 11

Posted 21 October 2011 - 02:50 PM

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
0

#23 User is offline   Praveen J 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 29-December 11

Posted 15 March 2012 - 11:55 PM

Hi Pentium10,

Does this extension work on page size also.

Regards,
Praveen J.
0

#24 User is offline   Splainiac 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 25-April 12

Posted 25 April 2012 - 01:19 PM

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();
            }
        }
    }

1

#25 User is offline   Praveen J 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 29-December 11

Posted 29 April 2012 - 11:40 PM

View PostSplainiac, on 25 April 2012 - 01:19 PM, said:

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
0

#26 User is offline   Soter 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 04-December 11

Posted 02 May 2012 - 01:55 AM

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

private function doReadSave() {
//reset pageParam if user clicks on first page.
$key1 = get_class($this->owner).'_page';
if (!isset($_GET[$key1]) && isset($_GET['ajax'])){
$_GET[$key1] = 1;
}


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

View PostPraveen J, on 29 April 2012 - 11:40 PM, said:

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

0

#27 User is offline   Praveen J 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 29-December 11

Posted 02 May 2012 - 02:14 AM

View PostSoter, on 02 May 2012 - 01:55 AM, said:

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

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') {
...............



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
0

#28 User is offline   Soter 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 04-December 11

Posted 02 May 2012 - 04:11 AM

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;
}
...



View PostPraveen J, on 02 May 2012 - 02:14 AM, said:

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

This post has been edited by Soter: 02 May 2012 - 04:12 AM

1

#29 User is offline   Praveen J 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 29-December 11

Posted 02 May 2012 - 04:26 AM

View PostSoter, on 02 May 2012 - 04:11 AM, said:

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. :) :) :)
0

#30 User is offline   Soter 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 04-December 11

Posted 02 May 2012 - 06:31 AM

Hi,

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

This should work http://www.ramirezco...-for-cgridview/

Not tested

If success please post it :D

kind regards,
Soter

View PostPraveen J, on 02 May 2012 - 04:26 AM, said:

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. :) :) :)

0

#31 User is offline   Praveen J 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 29-December 11

Posted 02 May 2012 - 06:46 AM

View PostSoter, on 02 May 2012 - 06:31 AM, said:

Hi,

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

This should work http://www.ramirezco...-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.yiiframew...ension/pagesize for custom grid size. Wanted the remember filters work for that too.. ;) :)

Thanks You,
Praveen J.
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users