Friday, February 15, 2013

How to set number of page buttons in Yii CLinkPager for CActiveDataProvider

Sometimes, for mobile versions for example, in Yii's CActiveDataProvider is needed to reduce standard page buttons number (it's 10). The maxButtonCount that located in CLinkPager will do it. But how to get to this variable from CActiveDataProvider?

In the view:
$this->widget('zii.widgets.CListView',array(
      'dataProvider'=>$dataProvider,
      'pager' => array(
               'maxButtonCount'=>Yii::app()->controller->isMobile?4:10,
                ),
));
If you're using YiiBooster dont' forget to add to the pager:
    'class'          => 'bootstrap.widgets.TbPager',

5 comments: