How to return to current page in GridView?

Hello,

I have a button that performs an action and redirects back to admin.php

If I am on page 3 and press the button I get redirected back to page 1.

How can I redirect back to page 3?

Thanks

You can use this extension instead of a regular CGridView:

extension/rrviews/

Thanks,

Is there a way to do this with the current CGridView?

Yes, there is. But I am certain that you’ll end up doing the same thing as RedRabbit did. :)

One solution would be to turn off javascript:


'ajaxUpdate'=>false

But that’s probably not what you wanted.

this is a lot harder than it needs to be.

I am trying to code the page value in CButtonColumn.




$page = Yii::app()->getRequest()->getParam('Prjmaster_page',false);


'template' => '{view}{update}{checkout}{checkin}',

   'buttons' => array(

update' => array(

									'visible'=>'$data->CHKFLAG=="Y"',

),

										

									'checkout' => array(

       'lable' => 'Check Out',

										'visible'=>'$data->CHKFLAG<>"Y"',

										'url'=>'array("prjmaster/CheckOut","id"=>$data->ID)',

       'imageUrl' => 'images/lock.jpg',

                                        ),

'checkin' => array(

    'lable' => 'Check In',

											'visible'=>'$data->CHKFLAG=="Y" && $data->CHKOUTUSR == Yii::app()->user->name',

												'url'=>'array("prjmaster/CheckIn","id"=>$data->ID)',

    'imageUrl' => 'images/unlock.jpg',

                               ),

                                ),



Not sure how to code the $page in the url after the $data->ID

The problem is not Yii, it’s jQuery.

RedRabbit did AFAIK base his implementation on jQuery BBQ:

http://benalman.com/projects/jquery-bbq-plugin/

The problem is that jQuery tends to take away your back button…

Once you solve the page number issue, you need to solve filters…

Either turn off Ajax for your grid, or - better - use RRViews (because then you don’t have to reinvent that set of wheels). ;)

I tried RRViews, but when I redirect back to admin from page 5, I am still on page 1




$this->widget('ext.RRGridView', array(

	'id'=>'prjmaster-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,



When you navigate the grid, you should have something extra in the url, like ‘#modelname_page=2

If you don’t then it’s not set up correctly.

I have #Prjmaster_page=2 showing.

But my CButtonColumn link does not show this.

I am having trouble coding this into the link url.

Why do you need that?

If you want to redirect back use this:


$this->redirect(Yii::app()->request->getUrlReferrer());

I am on page 5, and that code sends me back to page 1.

Thanks for taking the time to help, I am getting frustrated. :)

If you get those anchors in your urls, then using the back button in your browser should take you to whatever page you were on before viewing an entry.

Did you try that?

Navigate grid, view entry, go back.

That should work, because the page number is in the url.

I takes a micro-second, because it will first go to the first page, then update the grid to match the page number in the url.

Did you clean out your assets? Just in case.

I can’t see any reasons why it shouldn’t work as your url is fine.

I am not using the back button.

I have a cbuttoncolumn that has a url that calls a function in my controller.

When I redirect from my function in my controller, I am back on the first page.

I want to redirect back to the page I was on in the gridview.

there is no other form, just the grid view.

When they click on my button in the gridview, I want to mark a record as checked out and return to this spot.

I am losing the current page value because I cannot encode it in the url.

I get variable not found.

Thanks

You are right: Yii::app()->request->getUrlReferrer() doesn’t take the full url into account.

The standard delete button has some jQuery attached to it:

http://www.yiiframework.com/forum/index.php?/topic/17236-setting-returnurl-for-cbuttoncolumn-button/page__p__85465

I have a feeling that you are going to need that, instead. :)

It’s a pity that get url referrer doesn’t do that…

I’ll see if XReturnable or similar history extension will do that job.

Since RRViews already solves the url/backbutton issue…

ok, thank you

I will need this functionality myself - I assumed that the referrer would contain any anchor, but apparently not.

The way to go is probably to duplicate whatever is done through jQuery for the delete button url.

Not even the standard view/edit buttons has that kind of code, which is odd (IMO).

I got this working by using some code from http://www.ramirezcobos.com/2010/12/19/how-to-maintain-pages-on-cgridview/




In controller


$page = Yii::app()->getRequest()->getParam('Prjmaster_page',1);

$params = $page? array('Prjmaster_page'=>$page) : array();


$route = $this->createUrl('admin',$params);

$this->redirect($route,true);






In admin view




		array(

			'class'=>'CButtonColumn',

			'deleteButtonOptions' => array('style'=>'display:none;'),

			'template' => '{view}{update}{checkout}{checkin}',

				'buttons' => array(

					'update' => array(

						'visible'=>'$data->CHKFLAG=="Y"',

					),

						

					'checkout' => array(

						'label' => 'Check Out',

						'visible'=>'$data->CHKFLAG<>"Y"',

						'url'=>'array("prjmaster/CheckOut","id"=>$data->ID,"Prjmaster_page"=>' . Yii::app()->getRequest()->getParam('Prjmaster_page',false). ')',

						'imageUrl' => 'images/lock.jpg',

						),


						'checkin' => array(

								'lable' => 'Check In',

								'visible'=>'$data->CHKFLAG=="Y" && $data->CHKOUTUSR == Yii::app()->user->name',

								'url'=>'array("prjmaster/CheckIn","id"=>$data->ID,"Prjmaster_page"=>' . Yii::app()->getRequest()->getParam('Prjmaster_page',false). ')',

							'imageUrl' => 'images/unlock.jpg',

						),

				),

		),