How to implement custom Pagination?

I am new to Yii. I want to implement custom pagination. I want to change the CSS and the layout. How do I change the CSS of the page numbers and the layout of pagination. I want to show the paging layout like below

<< < 1 2 3 4 > >> instead of default layout provided by Yii like this…[previous] 1 2 3 4 [next].

I am using zii.widget.cLIstview to disply the data. Here is my code…


   $this->widget('zii.widgets.CListView', array(

    			'dataProvider' => $categoryProjects,

    			'itemView' => '_itemDetailsView',			

    			'ajaxUpdate'=>false,

    		));



Can anyone please tell me how do I start with it? I’ve seen some posts but unable to get right information.

Thanks in advance.

Hi Mooni and welcome.

To accomplish what you are after…


'pager'=>array(

   'class'=>' ',  // use if you want to extend CLinkPager

   'cssFile'=>false,  // to redirect from using the css file in the framework.  

                    // Make sure you load your defined css file as you would with any other

   'header'=>'',

   'firstPageLabel'=>' ',  //fill in the following as you want

   'prevPageLabel'=>' ',

   'nextPageLabel'=>' ',	

   'lastPageLabel'=>' ',

),

Hi enfield,

Thanks for the reply. To do the paging like << < 1 2 3 4 > >> I’ve set the parameters like below.


'firstPageLabel' => $this->$beginPage, 

                            'prevPageLabel'  => '<', 

                            'nextPageLabel'  => '>', 

                            'lastPageLabel'  => '>>',  

How do I set the parameters for the paging layout of this type < 1…5 6 7 8 9 …30 >. Suppose if I have 30 pages, I want to show the first page number, last page number and show only 5 pages numbers every time. like below

< 1…5 6 7 8 9 …30 >

Thanks in advance.

Hey Mooni,

Welcome on my behalf as well. You can find out all the answers to your questions by looking at the CPagination code or consulting the Yii class reference.

If you want to do changes to the page functionality you have to use your own pagination class that preferably extends CPagination and simply overrides the required methods. If you end up doing this you can specify your own pager class for e.g. CListView’s pager options by setting the ‘class’ property.

Hope this helps.

Thanks Chris. I am completely new to Yii. Could you please provide some sample code or example on how to start with it. that would really help me a lot. Thanks again.

Hope this will help you