YII で CGridView のページネーションをスタイリングするには?
cgridview では、ページャーを pic ごとに表示しています。
次の方法でページャーの位置を表示したいと思います。
最初 前へ 1 2 3 4 5 6 7 8 9 10 次へ 最後へ
「ページに移動:」を削除したい。
どうすればいいですか?
header
ページャーのプロパティを空の文字列に設定するだけです。
例:
$this->widget('zii.widgets.CGridView', array(
// ...other properties here...
'pager' => array('class' => 'CLinkPager', 'header' => ''),
));
スタイルを変更するだけでよい場合は、独自のcssファイルを作成してgridViewに適用する必要があります(投稿の最後を参照)。ただし、変更がそれよりも深い場合は、ポケットベルを拡張する必要があります。
私はずっと前にこれを行いました:私は自分のニーズに合うようにリンクページャーを拡張しました。ディレクトリに、components
新しいポケットベルを作成しました。
class PagerSA extends CLinkPager
私が望むものに合うようにいくつかのメソッドを書き直したところ(変更は本当に小さいです)。これが例として取り上げることができる私のコードです。私が言ったように、私は元のポケットベルから本当にいくつかのことを変更しました。ポケットベルがまたはと大きく異なる場合は、CLinkPager
拡張CListPager
する必要がありますCBasePager
class PagerSA extends CLinkPager
{
const CSS_FIRST_PAGE='first';
const CSS_LAST_PAGE='last';
const CSS_PREVIOUS_PAGE='previous';
const CSS_NEXT_PAGE='next';
const CSS_INTERNAL_PAGE='page';
const CSS_HIDDEN_PAGE='hidden';
const CSS_SELECTED_PAGE='selected';
/**
* @var integer maximum number of page buttons that can be displayed. Defaults to 10.
*/
public $maxButtonCount=5;
/**
* @var string the text label for the next page button. Defaults to 'Next >'.
*/
public $nextPageLabel;
/**
* @var string the text label for the previous page button. Defaults to '< Previous'.
*/
public $prevPageLabel;
/**
* @var string the text label for the first page button. Defaults to '<< First'.
*/
public $firstPageLabel;
/**
* @var string the text label for the last page button. Defaults to 'Last >>'.
*/
public $lastPageLabel;
/**
* @var string the text shown before page buttons. Defaults to 'Go to page: '.
*/
public $header;
/**
* @var string the text shown after page buttons.
*/
public $footer='';
/**
* @var mixed the CSS file used for the widget. Defaults to null, meaning
* using the default CSS file included together with the widget.
* If false, no CSS file will be used. Otherwise, the specified CSS file
* will be included when using this widget.
*/
public $cssFile;
/**
* @var array HTML attributes for the pager container tag.
*/
public $htmlOptions=array();
/**
* Initializes the pager by setting some default property values.
*/
public function init()
{
if($this->nextPageLabel===null)
$this->nextPageLabel=Yii::t('yii','Suivante >');
if($this->prevPageLabel===null)
$this->prevPageLabel=Yii::t('yii','< Précédente');
if($this->firstPageLabel===null)
$this->firstPageLabel=Yii::t('yii','<< Première');
if($this->lastPageLabel===null)
$this->lastPageLabel=Yii::t('yii','Dernière >>');
if($this->header===null)
$this->header=Yii::t('yii','');
if(!isset($this->htmlOptions['id']))
$this->htmlOptions['id']=$this->getId();
if(!isset($this->htmlOptions['class']))
$this->htmlOptions['class']='yiiPager';
}
/**
* Creates the page buttons.
* @return array a list of page buttons (in HTML code).
*/
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,self::CSS_FIRST_PAGE,$currentPage<=0,false);
// prev page
if(($page=$currentPage-1)<0)
$page=0;
$buttons[]=$this->createPageButton($this->prevPageLabel,$page,self::CSS_PREVIOUS_PAGE,$currentPage<=0,false);
//2 first pages
if($currentPage==3)
{
$buttons[]=$this->createPageButton(1,0,self::CSS_INTERNAL_PAGE,false,0==$currentPage);
$buttons[]= ' ... ';
}
if($currentPage>3)
{
$buttons[]=$this->createPageButton(1,0,self::CSS_INTERNAL_PAGE,false,0==$currentPage);
$buttons[]=$this->createPageButton(2,1,self::CSS_INTERNAL_PAGE,false,1==$currentPage);
$buttons[]= ' ... ';
}
// internal pages
for($i=$beginPage;$i<=$endPage;++$i)
$buttons[]=$this->createPageButton($i+1,$i,self::CSS_INTERNAL_PAGE,false,$i==$currentPage);
//3 lasts pages
if($endPage<$pageCount-2)
{
$buttons[]= ' ... ';
for($i=$pageCount-2;$i<=$pageCount-1;++$i)
$buttons[]=$this->createPageButton($i+1,$i,self::CSS_INTERNAL_PAGE,false,$i==$currentPage);
}
if($endPage==$pageCount-2)
{
$buttons[]= ' ... ';
$buttons[]=$this->createPageButton($pageCount,$pageCount-1,self::CSS_INTERNAL_PAGE,false,$pageCount-1==$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($this->lastPageLabel,$pageCount-1,self::CSS_LAST_PAGE,$currentPage>=$pageCount-1,false);
return $buttons;
}
}
次に、それをcグリッドビューに適用するには、次のようなものを配置する必要があります。
'pager' => array(
'class' => 'SaAdminPager',
'cssFile'=>'/themes/version_3/css/widgets/adminPager.css',
'header'=>'',
),
'pagerCssClass'=>'pagination pagination-centered',