0

This is a very strange situation to me. I have a CSqldataprovider to handle my pagination.

According to documentations and examples it works almost correct. It calculates correct the number of pages based on the totalitemcount and pagesize. It shows the first page perfectly fine but when I click on the next page link it doesn't show any records. When I do var_dump on $this->dataProvider->getData() it shows an empty array on every other page than the first page...

My code for my pagination is below:

$result = Yii::app()->db->createCommand($sqlData)->queryAll();
$pages = new YMPagination(count($result));
    $pages->pageSize = Yii::app()->params['itemsPerPage'];
    $this->dataProvider = new CSqlDataProvider($sqlData, array(
        'totalItemCount'=>count($result),
        'sort'=>array(
            'attributes'=>array(
                'recept_id',
            ),
        ),
        'pagination'=>$pages,
    ));
$result = $this->dataProvider->getData();

If there is someone who knows what I am doing wrong... please tell me :)

Kind regards,

Pim

zishe
  • 10,665
  • 12
  • 64
  • 103
PimD1988
  • 307
  • 5
  • 14
  • I had the same issue using SQL SERVER.. look at this post if it solves your problem.. http://stackoverflow.com/questions/23389261/yii-pagination-result-using-csqldataprovider/23430493#23430493 – neophyte Jun 24 '14 at 13:29

1 Answers1

0

first of all, both

$result = Yii::app()->db->createCommand($sqlData)->queryAll();

and

$result = $this->dataProvider->getData();

are doing the same thing, remove one of them

second if you want the count of items, simply write a count query:

$count = Yii::app()->db->createCommand('select count(*) from myTable')->queryScalar();

instead of

count($result)

lastly make sure that you always get to these options by default, I mean not to have if statements that make the code not to reach block of dataproviders code

Developerium
  • 7,155
  • 5
  • 36
  • 56