[EXTENSION] remember-filters-gridview This extensions helps you to remember/store filter values of GridViews
#22
Posted 21 October 2011 - 02:50 PM
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
#23
Posted 15 March 2012 - 11:55 PM
Does this extension work on page size also.
Regards,
Praveen J.
#24
Posted 25 April 2012 - 01:19 PM
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();
}
}
}
#25
Posted 29 April 2012 - 11:40 PM
Splainiac, on 25 April 2012 - 01:19 PM, said:
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
#26
Posted 02 May 2012 - 01:55 AM
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') {
...............
Praveen J, on 29 April 2012 - 11:40 PM, said:
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
#27
Posted 02 May 2012 - 02:14 AM
Soter, on 02 May 2012 - 01:55 AM, said:
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
#28
Posted 02 May 2012 - 04:11 AM
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;
}
...
Praveen J, on 02 May 2012 - 02:14 AM, said:
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
#29
Posted 02 May 2012 - 04:26 AM
Soter, on 02 May 2012 - 04:11 AM, said:
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
#30
Posted 02 May 2012 - 06:31 AM
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
kind regards,
Soter
Praveen J, on 02 May 2012 - 04:26 AM, said:
Hehe.. That works great. Thanks alot for the help
#31
Posted 02 May 2012 - 06:46 AM
Soter, on 02 May 2012 - 06:31 AM, said:
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
kind regards,
Soter
Hi Soter,
Hehe..
Thanks You,
Praveen J.

Help












