Hi I wanted to remove the previous link from the first page and next link from the last page.
So I did the following,
Step 1 :
Create a php file under the extensions directory. Something like this
extensions/PagerHack/myPager.php
Now write a class inside this file which extends the CLinkPager that comes default with your app.
class myPager 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($this->firstPageLabel,0,$this->firstPageCssClass,$currentPage<=0,false);
// prev page
if(($page=$currentPage-1)<0)
$page=0;
//Riyaz: if we are in 1st page, lets not show the previous link
if($currentPage>0)
$buttons[]=$this->createPageButton($this->prevPageLabel,$page,$this->previousPageCssClass,$currentPage<=0,false);
// internal pages
for($i=$beginPage;$i<=$endPage;++$i)
$buttons[]=$this->createPageButton($i+1,$i,$this->internalPageCssClass,false,$i==$currentPage);
// next page
if(($page=$currentPage+1)>=$pageCount-1)
$page=$pageCount-1;
//Riyaz: if we are already in last page, lets not show the next link
if($currentPage+1 < $pageCount)
$buttons[]=$this->createPageButton($this->nextPageLabel,$page,$this->nextPageCssClass,$currentPage>=$pageCount-1,false);
// last page
$buttons[]=$this->createPageButton($this->lastPageLabel,$pageCount-1,$this->lastPageCssClass,$currentPage>=$pageCount-1,false);
return $buttons;
}
Look below the next and previous link creation comments.
The Previous link, I have removed it when we are in first page.
Similarly Next link, I have removed it when we are already in the last page.
Step 2:
Combine your pager with CGridview or CListView as follows
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'trainingplan-grid',
'pager'=>'ext.PagerHack.myPager',
Note the last line, I have called my newly created class as the pager.
I wanted to share this tip because there are many people who are still using CSS / JAVASCRIPT to hide this or so. So thought this would be the best solution.
Cheers !