CListView - Current Page and Refreshing

Hello gurus,

I have a button that toggles a db boolean between true/false in my list view. At current, the button links you to another action of the controller. That action changes the boolean, saves the model, and brings you back to the page you came from. However, this resets the list view pager back to page 1. When you’re going through thousands of records setting this boolean, having to go through a number of pages to get back to where you were has become quite annoying.

Is there a way of doing this inside the list view itself? Ideally, it would be nice for the button to call the boolean toggle action via AJAX, and then refresh the current page of the list view.

Thanks!

Matt

Nobody?

Yes.

Put the page number post variable in the out bound links.

Then create a go back link with the page number in it.

Can’t remember what the post params are called.

But if you’re using Firebug or similar you’ll be able to see them.

You can do the same for filters, etc.

It’s not easy when the grid is ajax-powered, but it works.

Thanks jacmoe,

That is a solution that I had thought about as well, but on one of my pages I have more than one listview. Additionally, I don’t see a way of getting the current page number as a php variable so I can append it to the links in my listview partial view.

Do you use Firebug?

Look at the Net tab - you might have to enable it first.

There you’ll see the hidden url, like:


http://127.0.0.1/projects/bugitor/issues?projectname=Bugitor&Issue_page=2&ajax=issue-grid

As you can see, I need to pass Issue_page=2 in my url to get back to the second page I was on when Firebug grabbed the request headers

Yes, the url seems to be listviewID_page=$somepage, which was as far as I had gotten as well. However, aside from reading the pager manually in Firebug, I’m unsure how I can access the CPagination object associated with the dataProvider so I can determine within the listview partial view itself what page I’m on, and echo that to the appropriate links.

Something like:




<a href="index.php?r=boolswitch/toggle&page=<?php echo $thePageWeAreOn; ?>">Swap the boolean</a>



I just don’t know how to get $thePageWeAreOn. I tried:




$pager = $this->dataProvider->getPagination();

$thePageWeAreOn = $pager->getCurrentPage();



But, I think I’m having a scope problem. $this, within the listview partial view, refers to the page controller, and not to the widget. So, that’s where I’m stuck currently.

Thanks again for your suggestions so far!

Matt

For anyone who needs the answer to this, I’ve found a solution. $widget will return your CListView object within the partial view, which has an associated dataProvider. To get your page number, do this:




$pagination = $widget->dataProvider->getPagination();

$currentPage = $pagination->getCurrentPage();



I had heard that Yii was young but hadn’t realized just how young; I figured I had overlooked something simple (I had), but am surprised that the community didn’t have the answer. Nevertheless, I am finding it mostly a joy to work with, and hope that it continues to grow.

Thanks to those that chimed in.

-Matt

As you say, Yii is young, but the documentation is complete and good written.

The difficoult point is how to read (and, more difficoult, hot to teach how to read).

For example, the question about the variable $widget was here.

Now the real question is, for future, where to look, how to find?

Frankly speaking I have no idea how I find in guide, maybe is just experience.

The best advice is to look a bit in api, and if not found to ask in the forum…

I agree with zaccaria

At the time I was beginning to use Yii… the documentation was not clear to me… the class reference (api) even less

I didn’t know where to look or what to search for… and how is all this connected…

But with time it just "clicked" in my brain… and now the class reference is like a holly bible for Yii…

So it’s just a matter of time to get a bit of experience and to understand the Yii concepts…

In the meantime, here is the forum…

@Nishmaster

Isn’t it better that you solved yourself the problem… it’s more rewarding in the end… and you get a better understanding of how Yii is working… and that’s just the kind of experince I’m tolking that you need to better understand it… :)

Can you explain this in more details?

Thank you.

Now I understand. $widget variable can be used just like we use $data variable. :)

Many thanks to zaccaria and Nishmaster.