Yii Framework Forum: Bring User Back To Where He Was In Cgridview - Yii Framework Forum

Jump to content

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

Bring User Back To Where He Was In Cgridview Rate Topic: -----

#21 User is offline   Trejder 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,201
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 07 May 2013 - 03:14 AM

View Postjacmoe, on 06 May 2013 - 03:48 PM, said:

What you think you are seeing is the grid without Ajax, but you are actually mistaken.
If you are using a slow db connection you can see that the spinner is spinning, indicating that it is Ajax/HTML5 which changes the url.

R U 100% sure? I'm on a quite fast connection (localhost, dev environment), I don't see spinner at all (TbGridView seems to be dropping this idea), but I do clearly see, that something is added to my URL (actually, not something, but exactly the same URL parts, as when CGridView is not using AJAX-update). Speeds are nearly or exactly the same, no matter if I use enableHistory or not. So I assume, that my CGridView dropps out of AJAX-update, when I'm using enableHistory, only basing on my URL changes. And the fact, that when enableHistory is turned on, I see spinner spinning in my Chrome tab's icon.

But, this is side-talk, whether this works AJAX-less or am I only thinking it is. The key problem here is, that either I'm missing something, or enableHistory does not work at all. I have HTML5-enabled browser and I can't reproduce "persist state of grid across page revisits", as I shown on my examples.
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#22 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,101
  • Joined: 16-February 11
  • Location:Japan

Posted 07 May 2013 - 05:42 AM

The basic concept of "enableHistory" is that your browser's address bar is updated to the exact url even when the page is updated by an ajax call.

Usually the get parameter like "Model_page=2" for pagination will not appear in your browser's address bar when the grid is updated by ajax. But when you set "enableHistory" to true, it will appear. And every url of the ajax updated page will be recorded as a history in the browser.

This is quite convenient for users, because the click of the BACK button will bring him/her back to the exact place where he/she was before. And the user can bookmark the exact page, too.
0

#23 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,656
  • Joined: 10-October 10
  • Location:Denmark

Posted 07 May 2013 - 06:19 AM

Enabling HTML5 history for your grid is not side-talk Trejder. :)
It does what you want it to: the user can use the back button, and/or you can use the getUrlReferrer method.
"Less noise - more signal"
0

#24 User is offline   Daniel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 237
  • Joined: 26-September 09

Posted 07 May 2013 - 08:34 AM

Hi,

This is what I usually used on almost of all my projects. Even, I put that as gii template model+crud. I hope someday can be the standard feature for CGridView. Here is the link of My wiki

Cheers,

Daniel

PS: I welcome feedback for my wiki.
0

#25 User is offline   Trejder 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,201
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 19 July 2013 - 08:12 AM

Reopening old topic...

View Postjacmoe, on 07 May 2013 - 06:19 AM, said:

Enabling HTML5 history for your grid is not side-talk Trejder.
It does what you want it to: the user can use the back button, and/or you can use the getUrlReferrer method.

I'm getting the entire idea of using back button, but only partial of getUrlReferrer. Somebody would have to enlighten me a little bit.

1. Use-case scenario number one -- getUrlReferrer used in "Cancel" button code in update-form for any model:

a) user is on a grid, making mess (sorting, paginating, etc.), enableHistory is true, so all his or her mess is reflected in the URL,

B) user clicks on "edit" and is redirected to update form,

c) user clicks on "Cancel", getUrlReferrer contains grid URL so redirect (and while idea) works just perfectly.

Amen! :]

2. Use-case scenario number one -- getUrlReferrer used in "Submit" button code in update-form for any model:

a) user is again in update form and getUrlReferrer again contains grid URL,

B) user clicks "Submit", controller saves model and getUrlReferrer now contains update-form URL, not grid-one,

c) redirect after save (and whole thing) fails, as user is redirected back to update form, not to grid.

This second scenario concerns me. Do I get it right, that I don't get it done basing on just pure, internal Yii toys? That this is my responsibility to transport correct grid URL from update-from to controller's model save code? For example, using additional model's field?
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#26 User is offline   Stephen Miles 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 04-June 13

Posted 19 July 2013 - 09:17 AM

Trejder

I am looking into doing something like this and have just tried setting enableHistory to true in the CGridView widget. From what softark said it should update the URl but it is not happening. Have you got it working? and if so how did you do it? I'm using Firefox 22 on Ubuntu.

Thank you for any help.

Stephen

[edit]

I can see it working for the pagination but I want it to also work for the search, any ideas?
0

#27 User is offline   Trejder 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,201
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 29 July 2013 - 07:11 AM

View PostStephen Miles, on 19 July 2013 - 09:17 AM, said:

I can see it working for the pagination but I want it to also work for the search, any ideas?

Yes, I have it working for all: sorting, pagination and filtering / searching.

All I did to enable this, was to add:

'enableHistory'=>TRUE

to definition of each CGridView, where I wanted to use it. Yii did all the rest and since enabling this, I was able to see extra additions to URL to make this working.

As for processing the results (currently I have this only for Cancel buttons, I'm working over submit buttons), I had such cancel button:

$this->widget('bootstrap.widgets.TbButton', array
(
	'label'=>'Anuluj',
	'icon'=>'remove',
	'url'=>Yii::app()->createUrl('content/manage/index'),
	'htmlOptions'=>array('style'=>'margin-left: 5px')
));

so it was always redirecting user to first page of index, no matter, what he or she was doing.

I changed above code to:

$url = Yii::app()->request->getUrlReferrer();
$url = is_null($url) ? Yii::app()->createUrl('content/manage/index') : $url;

$this->widget('bootstrap.widgets.TbButton', array
(
	'label'=>'Anuluj',
	'icon'=>'remove',
	'url'=>$url,
	'htmlOptions'=>array('style'=>'margin-left: 5px')
));

to make use of Yii's presist state feature. This code should be self-explanatory. It checks, if there is anything in URL refferer, and if there is, it redirects user there. If not, it again redirects it to default (first page) screen.

This is very odd, that you have it working for pagination only and not for sorting or searching. This should either work for all or for non. I don't know what to advise you. Double check, if you have AJAX update of CGridView enabled and if you don't have more than one CGridView with "enableHistory" turned on, on one page / in one view. As docs says, that strange thing may happen in this case.
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
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