pagination not displaying complete sets of rows

I am having trouble getting all rows to display in each page. The total number of rows is 308, and pageSize is set to 100, but each of the 4 pages show a subset of 100 records, varying in each set, never more than 16 rows, sometimes as few as 1 per page. Did I forget to enable something or set a parameter?

In the view:




<?php


class AuthorizationGridView extends CGridView {

        public $YearSel;

}


// ...


$this->widget('AuthorizationGridView', array(

        'id'=>'auth-grid',

        'dataProvider'=>$model->authsearch($Year),

        'YearSel' => $Year,

        'filter'=>$model,

        "htmlOptions" => array(

                'style'=>'width: 1100px;'

        ),

        'columns'=>array(

...

)));




// In the model:


         public function authsearch($yr)

        {

            // MAIN QUERY CONDITION

            $criteria=new CDbCriteria;

            $criteria->addCondition('t.MRPLid IS NOT NULL');

// ...

            return new CActiveDataProvider($this, array(

                'criteria'=>$criteria,

                'pagination' => array(

                        'pageSize' => 100,

                ),

                'sort'=>array(


                  'defaultOrder'=>'Request_id DESC',

                        'multiSort'=>true,


                    'attributes'=>$attrAry,

                ),

            ));

        }

I wouldn’t normally want pagination for 300 rows, but I resorted to it after experiencing a memory fault with memory_limit set to 500M and then again at 600M, which seems to be an excessive amount of memory needed for 300 rows. 900M resolved the memory fault, but I thought I’d try pagination to avoid having to set an arbitrary memory_limit that still might cause a fault in the future. The table I’m displaying has about 20 columns, some columns contain attributes in the model, some columns follow foreign keys to an attribute in a definition table, some columns are computed by functions in the model.

So, I don’t know why the display is utilizing such an excessive amount of memory to begin with, and also why pagination is not working properly.

Edit: code formatting added

[color="#556B2F"]/* Moved from "2.0" to "1.1" */[/color]

Hi MaryR,

Your model has one-to-many relations to other models, doesn’t it? And you include them in your query for the grid view, don’t you?

It is a known problem that you may get a wrong pagination result when you deal with a has-many relation in active record query.

The following wiki article may give you some hints.

Search by a HAS_MANY relation (http://www.yiiframework.com/wiki/428/drills-search-by-a-has_many-relation-in-yii-1-1)

My model has only BELONGS_TO and HAS_ONE relations, no HAS_MANY. In further research, I read something about pagination not working with CActiveDataProviders, that CArrayDataProvider should be used. Is this correct?

Even if your model doesn’t have HAS_MANY relations, your query could join other tables that have 1:N relation to the main table. Are you really sure that your query doesn’t involve HAS_MANY relation?

I would like to see how you construct the criteria.

As for CArrayDataProvider, it won’t be a help in this case, because it requires a lot more memory than CActiveDataProvider. And it’s only a guess, but I think that some kind of wrong design in the query criteria might be the cause of the huge memory consumption.

Thanks for the feedback! I’ll forget pagination, since I’m not a fan and it’s complicating the issue. I’ll take a closer look at my criteria to look for inefficiencies and get back to you on that.