Pagination issue

Hello, I have a CGridView set up with $dataProvider->pagination->pageSize = 8 and $dataProvider->totalItemCount = 8. So basically I want to only display 8 results with no pagination. Everything works great except when I sort. The behavior that I want is that if you sort by a column, it will only sort the 8 items displayed. However, it actually sorts the entire list of results, not just the 1 page that is displayed. Any solution to this? Thanks.

can you display your dataprovider call with csort

All I do is:

$dataProvider = $model->search();

$dataProvider->pagination->pageSize = 8;

$dataProvider->totalItemCount = 8;

I haven’t added any custom CSort stuff, I’m not very familiar with that. Can I use that to make it only sort those 8 items?

I see you using a CGridView you have to define pagination in model->search(),


  public function search(){

                $criteria=new CDbCriteria;

                $criteria->condition = 'user_id='.Yii::app()->user->id;






                return new CActiveDataProvider(get_class($this), array(






                        'sort' => array(

                        'defaultOrder' => 'attribute',

                          'attributes' => array(


                          'attributename' => array(

                                    'asc' => 'attributename',






I don’t think so, because the pagination the way I do it works. It only shows 8 items and 1 page, which is what I want. The search returns a dataProvider so if I save $model->search() to $dataProvider and edit pagination that way it works just fine. The issue doesn’t really have to do with getting the pagination to work normally. I guess everything works as intended.

However, I am trying to alter the functionality of the CGridView sort so that it only sorts the 8 items in the initially displayed table. What I mean is, with totalItemCount=8, it will only show 8 items, even if there are normally 100 results. I want it so that when I sort it ONLY sorts those 8 items, excluding the other 92 items that didn’t show up originally. Thanks.

In first case i dintnt understand what you wont :) if you wont to eject the all 92 querys you have to limit criteria then $criteria->limit = 8;

Hmm for some reason it’s still grabbing the other values, but thank you! I will continue to look into this ->limit business.

it will not work $this->limit, you have to use on criteria in your model search you can`t apply to cactivedataprovider.

Thats why i´m suggest you to use all options of CActivedataprovider in $model->search() :)