finzaiko
(Finzaiko)
September 11, 2012, 4:36am
1
For example, we have thousands of data which we will show in Cgridview automatically CLinkPager appear 1 2 3 4 5 6 7 8 9 10 and so on… How can I show 5 link number only ( 1 2 3 4 5 …) ?
Thanks for sharing experience with yii.
danilsk
(Martenmarten)
September 11, 2012, 5:02am
2
Finzaiko:
For example, we have thousands of data which we will show in Cgridview automatically CLinkPager appear 1 2 3 4 5 6 7 8 9 10 and so on… How can I show 5 link number only ( 1 2 3 4 5 …) ?
Thanks for sharing experience with yii.
You’d have to extend CLinkPager and override it’s createPageButtons method.
class CNewLinkPager extends CLinkPager{
protected function createPageButtons()
{
if(($pageCount=$this->getPageCount())<=1)
return array();
list($beginPage,$endPage)=$this->getPageRange();
$currentPage=$this->getCurrentPage(false); // currentPage is calculated in getPageRange()
$buttons=array();
// first page
$buttons[]=$this->createPageButton(1,0,self::CSS_FIRST_PAGE,$currentPage<=5,false);
$buttons[]=$this->createPageButton("...", 0, "ellipsis", $currentPage <= 6, false);
// prev page
if(($page=$currentPage-1)<0)
$page=0;
$buttons[]=$this->createPageButton($this->prevPageLabel,$page,self::CSS_PREVIOUS_PAGE,$currentPage<=0,false);
// internal pages
for($i=$beginPage;$i<=$endPage;++$i)
$buttons[]=$this->createPageButton($i+1,$i,self::CSS_INTERNAL_PAGE,false,$i==$currentPage);
// next page
if(($page=$currentPage+1)>=$pageCount-1)
$page=$pageCount-1;
$buttons[]=$this->createPageButton($this->nextPageLabel,$page,self::CSS_NEXT_PAGE,$currentPage>=$pageCount-1,false);
// last page
$buttons[]=$this->createPageButton("...",0,"ellipsis",$currentPage >= $pageCount-6,false);
$buttons[]=$this->createPageButton($pageCount,$pageCount-1,self::CSS_LAST_PAGE,$currentPage>=$pageCount-1,false);
return $buttons;
}
}
finzaiko
(Finzaiko)
September 11, 2012, 8:02am
3
Hi, Dan S.K thanks for advance, I try your code not work properly, finally I found a solution.
I extend CLinkPager as Dan S.K suggest me but its simple code
class MyLinkPager extends CLinkPager
{
public $maxButtonCount=5;
public $cssFile = 'css/newpager.css'; // i want to show first and last link
}
create new css file I put in css folder, I just copy all css code located in [font="Courier New"]/yii/framework/web/widgets/pagers/pager.css[/font] [font="Arial"]into[/font] [font="Arial"]newpager.css, for more go here
register MyLinkPager class in CGridview
....
'filter'=>$model,
'pager' => array(
'class' => 'MyLinkPager',
),
.....
Done
[/font]
danilsk
(Martenmarten)
September 11, 2012, 4:23pm
4
Finzaiko:
Hi, Dan S.K thanks for advance, I try your code not work properly, finally I found a solution.
I extend CLinkPager as Dan S.K suggest me but its simple code
class MyLinkPager extends CLinkPager
{
public $maxButtonCount=5;
public $cssFile = 'css/newpager.css'; // i want to show first and last link
}
create new css file I put in css folder, I just copy all css code located in [font="Courier New"]/yii/framework/web/widgets/pagers/pager.css[/font] [font="Arial"]into[/font] [font="Arial"]newpager.css, for more go here
register MyLinkPager class in CGridview
....
'filter'=>$model,
'pager' => array(
'class' => 'MyLinkPager',
),
.....
Done
[/font]
Sorry, I thought you asked how to turn it into smth like 1 … 6 7 8 9 … 20
But in your case you could just pass it in the pager property and it’d override the default value
'pager' => array(
'maxButtonCount' => 5
),
finzaiko
(Finzaiko)
September 12, 2012, 1:36am
5
Sorry, I thought you asked how to turn it into smth like 1 … 6 7 8 9 … 20
But in your case you could just pass it in the pager property and it’d override the default value
'pager' => array(
'maxButtonCount' => 5
),
Ok Dan, Thanks a lot for your new solution, I just found out now