December 3, 2010, 12:49pm
I’m using CGridView with pagination and it’s a great widget. But pages are displayed in this way
1 2 3 4 5 6 7 8 9 10
It’s Ok when there are not too many pages, but what if there are 1000 pages or more? User will get tired of clicking page numbers to list all of them.
Is it posible to display page numbers like this
1 2 3 4 5 6 7 8 9 ... 20 21
December 3, 2010, 1:30pm
I think that is not possible to configure the pager like that.
You can write your own pager and then configure CGridView for use your one. There is the property ‘pager’=>‘class’ for this.
December 5, 2010, 1:30pm
Ok, I decided to follow zaccaria’s advice and made a little class that extends CLinkPager. I added to existing pager a dropdown list with page numbers. When you choose a number the corresponding page opens.
In my class (I called it ExtPager) I override just one method (createPageButtons()) from CLinkPager. Here is what I added to it
$pages = '';
$pages = $i+1;
$id = $this->controller->getUniqueId()."_ddpl";
$buttons = CHtml::dropDownList('pages','',$pages,array('class'=>'extpager','id'=>$id,'onchange'=>'valchange()'));
page = $('#$id').val();
url = '".$this->createPageUrl(1)."';
p = url.lastIndexOf('=');
new_url = url.substr(0,p+1);
window.location = new_url+page;
$url = Yii::app()->request->baseUrl.'/css/extpager.css';
It’s rather rough implementation (I’m not a great programmer you know
) but it works.
Another disadvantage of my code is that it does not use ajax like standard pager does(I just could not figure out how to make it use ajax).
To use my ExtPager do this:
save ExtPager.php in /protected/components;
save extpager.css in /css folder;
in your widget (e.g. CGridView) configuration add
And that’s all.
I know that there are many good programmers on our forum so please help to improve my class.
April 27, 2011, 10:38am
hello i’m trying to use your pagination script, it seems good to me, but i’ve got an error like this…
The system is unable to find the requested action "2".
it means cannot render page 2, even the first page when I back from page 2 to 1. do you have any clue… ?