How to set up shortcuts for pager in Yii?

I am new to Yii. I want to implement custom pagination. I want to change the appearance of the pager. How to change pager link shortcuts?

I want the links to display like this:

<< < 1 2 3 4 > >> 

instead of an appearance that looks like this:

 [first] [previous] 1 2 3 4 [next] [last] 

I use CListView to display the data that I set as follows:

 $this->widget('zii.widgets.CListView', array( 'dataProvider' => $categoryProjects, 'itemView' => '_itemDetailsView', 'ajaxUpdate'=>false, )); 

Can anyone tell me how to start with this? I saw several posts, but could not get the correct information.

Thanks in advance.

+7
source share
2 answers

You need to set the pager CListView property. By default, this is CLinkPager ; you do not need to change this (this component covers your needs), but you need to configure it:

 $this->widget('zii.widgets.CListView', array( 'dataProvider' => $categoryProjects, 'itemView' => '_itemDetailsView', 'ajaxUpdate' => false, 'pager' => array( 'class' => 'CLinkPager', 'firstPageLabel' => '<<', 'prevPageLabel' => '<', 'nextPageLabel' => '>', 'lastPageLabel' => '>>', ), )); 

Update: If you want to “bake” the aforementioned custom configuration for all kinds of lists in your application, you need to create a new CustomListView component obtained from CListView . So you need this class:

 Yii::import('zii.widgets.CListView'); class CustomListView extends CListView { public function init() { parent::init(); $this->pager = array( 'class' => 'CLinkPager', 'firstPageLabel' => '<<', 'prevPageLabel' => '<', 'nextPageLabel' => '>', 'lastPageLabel' => '>>', ); } } 

After that, you can simply use CustomListView as a list widget instead of zii.widgets.CListView .

+12
source

You can link to the link:

Yii2: How to customize the style of pagination and other shortcuts

Here you will get most of the settings for custom pagination shortcuts

+1
source

All Articles