CLInkPager First and Last buttons

The first and last buttons in CLinkPager are always given the class "hidden".

This is due to the logic used to determine their hidden state which in both cases always evaluates true.

Changing the logic to the same as used for the Previous and Next buttons gets them working.

Snippets from CLinkPager::createPageButtons()

Current (Yii 1.0.9) code

// first page

$buttons[]=$this->createPageButton($this->firstPageLabel,0,self::CSS_FIRST_PAGE,[color="#FF0000"]$beginPage<=0[/color],false);

|

|

// last page

$buttons[]=$this->createPageButton($this->lastPageLabel,$pageCount-1,self::CSS_LAST_PAGE,[color="#FF0000"]$endPage>=$pageCount-1[/color],false);

Altered code

// first page

$buttons[]=$this->createPageButton($this->firstPageLabel,0,self::CSS_FIRST_PAGE,[color="#2E8B57"]$currentPage<=0[/color],false);

|

|

// last page

$buttons[]=$this->createPageButton($this->lastPageLabel,$pageCount-1,self::CSS_LAST_PAGE,[color="#2E8B57"]$currentPage>=$pageCount-1[/color],false);

[/code]

is there any official solution for this problem?

The original code should be correct. $beginPage and $endPage here mean the first and last pages currently shown in the page buttons.

Therefore, the "first page" button will be hidden if the first page button is 1.

Note that the default css style coming with the pager set the first and last page buttons to be "display: none". You may want to override them if you want to show them.

How do I override the css provided by the standard component? I added


ul.yiiPager .first, ul.yiiPager .last {


display: inline;


}

in main.php, but since pager.css comes last when the page is rendered, my modification is overriden again.

What I do - since I don’t want the first and/or last buttons set to hidden - is create my own derived linkpager:





class CustomLinkPager extends CLinkPager

{

	protected function createPageButton($label,$page,$class,$hidden,$selected)

	{

		if($hidden || $selected)

			$class.=' '.($hidden ? self::CSS_HIDDEN_PAGE : self::CSS_SELECTED_PAGE);

                if($hidden)

                    return '<li class="'.$class.'"></li>';

                return '<li class="'.$class.'">'.CHtml::link($label,$this->createPageUrl($page)).'</li>';

	}

}



Now, they are not shown at all when they’re supposed to be not shown. ;)

I was able to get the “First” and “Last” links to show up by subclassing CLinkPager and using my own css. Full explanation with code example here: www.benjaminlhaas.com/blog/displaying-yiis-clinkpager-first-and-last-buttons (the forums won’t let me post a link)

As this questions is bound to come up from time to time, here is the solution:

add to your main.css:


#page ul.yiiPager .first,

#page ul.yiiPager .last

{

	display: inline;

}

if this does not work change #page to your container div ID