Yii Framework Forum: pagination not displaying complete sets of rows - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

pagination not displaying complete sets of rows Rate Topic: -----

#1 User is offline   MaryR 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 13-November 15

Posted 28 February 2018 - 09:20 PM

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
0

#2 User is online   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,639
  • Joined: 16-February 11
  • Location:Japan

Posted 02 March 2018 - 03:33 PM

/* Moved from "2.0" to "1.1" */

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.yiiframew...tion-in-yii-1-1)
0

#3 User is offline   MaryR 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 13-November 15

Posted 02 March 2018 - 08:55 PM

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?
0

#4 User is online   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,639
  • Joined: 16-February 11
  • Location:Japan

Posted 03 March 2018 - 02:46 AM

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.
0

#5 User is offline   MaryR 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 13-November 15

Posted 05 March 2018 - 09:12 AM

View PostMaryR, on 02 March 2018 - 08:55 PM, said:

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?



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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users