简体   繁体   中英

CGridView Yii add pagination textbox

I have a grid created with Yii framework CGridView widget.
How can I add in the grid view a "Go to page" field that takes the user input as the page number ?

Is there any automated way to do that?

I don't think there is any way built in.

My initial thought was that this should be simple to implement but it may be quite difficult to do this only on the client side. There's not much in the way of a JavaScript API for pulling pages, nor a way to build links on the client. It's all done on the server when the page is served, so that may be where this functionality has to go.

Maybe you should start by extending CLinkPager to output all possible page numbers and their links on the initial page render. It could then be stored in the data attribute of the CLinkPager base element, as JSON, and used in the page from there?

The actual client code to update the grid view with the new url shouldn't be too hard to shoehorn in somewhere, perhaps swap out one of the pagination buttons href attributes with the one you want to load, then replace the previous one after?

I think it'll still boil down to a hack unless you want to extend CLinkPager further to include a JS API?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM