Yii Framework Forum: Extend Clinkpager Example - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Extend Clinkpager Example Rate Topic: -----

#1 User is offline   riyazMuhammed 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 13-September 12
  • Location:Bangalore

Posted 18 March 2013 - 05:43 AM

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 ! :)
1

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 18 March 2013 - 06:13 AM

I do something extremely similar myself. Great tip! :)
"Less noise - more signal"
0

#3 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 18 March 2013 - 11:23 AM

Dear Riaz

I really appreciate you for sharing the tip with us.

In this regard, I want to share something with you.

By registering the following bit of css in admin.php, we can achieve the same functionality.

Yii::app()->clientScript->registerCss('last_first_hider','ul.yiiPager .hidden a
        {
	    display:none;
        }');


Regards.
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users