Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the number of items per page in a CGridView?

I have a project in Yii where there is a CGridView that by default shows 10 records per page. How can I set this to 100 records?

like image 284
Mick Segvezent Avatar asked Apr 19 '12 12:04

Mick Segvezent


2 Answers

You can configure in Search function of the Model like below:

public function search()
{
    $criteria=new CDbCriteria;

    $criteria->compare('id',$this->id,true);
    $criteria->compare('start_year',$this->start_year,true);
    $criteria->compare('end_year',$this->end_year,true);
    $criteria->compare('ref_lang_id',$this->ref_lang_id);
    $criteria->compare('submitted_at',$this->submitted_at,true);
    $criteria->compare('ref_submitted_user_id',$this->ref_submitted_user_id,true);

    return new CActiveDataProvider($this, array(
        'criteria'=>$criteria,
        'pagination' => array(
            'pageSize' => 30,
        ),
    ));
}
like image 136
Hoang-Viet Avatar answered Oct 28 '22 12:10

Hoang-Viet


Find in your view the place where the CGridView widget is being rendered, and configure the pagination property of the data provider:

$this->widget('zii.widgets.CGridView', array(
    'dataProvider' => array(
         /* other options for the data provider... */
        'pagination' => array('pageSize' => 100),
    ),
    /* other options for the grid view... */
));
like image 44
Jon Avatar answered Oct 28 '22 12:10

Jon