npager User can set up the pagination pageSize property in the CListView and CGridView

  1. Requirements
  2. Usage

NPager add a dropdownlist for the CListView and the CGridView. Whit this dropdownlist user can set up the pagination pageSize value.

The idea comes from a friend. Her name begins with N, so NPager the extension name.

Requirements

I created with Yii 1.1.10, but perhaps it working with older versions too.

Usage

demo

/* NListView */

//the action:

public function actionNListView()
{
    $dataProvider = new CArrayDataProvider($this->getArray(), array(
                'sort' => array(
                    'attributes' => array(
                        'id', 'settlement', 'type', 'population'
                    ),
                ),
                'pagination' => array(
                    'pageSize' => isset($_GET['pageSize']) ? $_GET['pageSize'] : 12,
                    // 12 is the default pageSize
                ),
            ));
    $this->render('NListView', array(
        'dataProvider' => $dataProvider,
    ));
}

/*the view's content:

defaults:
pagerlist => array(
  '10' => 10,
  '25' => 25,
  '50' => 50,
  '100' => 100,
  'all' => 'ALL', // you can use the zii dictionary
),
pagerlistCssClass => 'pager-list',
template => "{summary}\n{pagerlist}\n{pager}\n{items}",
textItemsPerPage => 'items per pages', // you can use the zii dictionary
*/
 
$this->widget('application.extensions.NPager.NListView', array(
    'dataProvider' => $dataProvider,
    'sortableAttributes' => array(
        'id', 'settlement', 'type', 'county', 'population'
    ),
    'itemView' => '_item',
    'pagerlist' => array(
        '4' => '4',
        '12' => '12',
        '20' => '20',
        '40' => '40',
        '80' => '80',
        '160' => '160',
        'all' => 'All',
    ),
));
?>
/*********************************************************************/

/*NGridView*/

//the action:

public function actionNGridView()
{
    $dataProvider = new CArrayDataProvider($this->getArray(), array(
                'sort' => array(
                    'attributes' => array(
                        'id', 'settlement', 'type', 'population'
                    ),
                ),
                'pagination' => array(
                    'pageSize' => isset($_GET['pageSize']) ? $_GET['pageSize'] : 10,
                    // 10 is the default pageSize
                ),
            ));
    $this->render('NGridView', array(
        'dataProvider' => $dataProvider,
    ));
}

/*the view's content:

defaults:
pagerlist => array(
  '10' => 10,
  '25' => 25,
  '50' => 50,
  '100' => 100,
  'all' => 'All', // you can use the zii dictionary
),
pagerlistCssClass => 'pager-list',
template => "{summary}\n{pagerlist}\n{pager}\n{items}",
textItemsPerPage => 'items per page', // you can use the zii dictionary
*/
 
$this->widget('application.extensions.NPager.NGridView', array(
    'dataProvider' => $dataProvider,
));

4 0
11 followers
807 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Developed by: TocsA
Created on: Jul 3, 2012
Last updated: 12 years ago

Downloads

show all

Related Extensions