Yii Framework Forum: Clistview Only Retuning 4 Results On First Page - Yii Framework Forum

Jump to content

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

Clistview Only Retuning 4 Results On First Page Rate Topic: -----

#1 User is offline   skworden 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 115
  • Joined: 14-June 12
  • Location:Virginia, USA

Posted 30 April 2013 - 10:34 AM

Hello all,

I am having a problem with my clistview. It is only returning 4 results on the first page and 10 on all the rest.

If i set the value it increases on the first page however it doesn't show the right number on the first page.

i.e. if i set it to 20 it shows 14 on the first page and 20 on all the rest. It also makes my queries go from 7 to 18.

If I add $critera->order = '...', it works right but increases my queries from 7 to 13

Anyone know why it's doing this and how i can fix it?

Current code:

<?php
	$current_user = Yii::app()->user->id;
	$criteria = new CDbCriteria();
	$criteria->together = TRUE;
	$criteria->with = array(
	'creator0', 'updater0', 'addonphotos');
	$criteria->condition = 't.status=:status';
	$criteria->params = array(':status' => 1);
        $criteria->order = 'create_date DESC';//If I don't have this portion it doesn't work 
	$dataProvider = new CActiveDataProvider(Addon::model(), array('criteria'=>$criteria, 
	
	));

	$this->widget('zii.widgets.CListView', array(
		'dataProvider'=>$dataProvider,
		'itemView'=>'_view',
		'id'=>'addonListView',
		'pager'=> array(
			'header' => '',
			'footer' => '',
			'firstPageLabel' => 'First Page',
			'prevPageLabel'  => 'Prev. Page',
			'nextPageLabel'  => 'Next Page',
			'lastPageLabel'  => 'Last Page',
		),
		'template'=>'{sorter}{items}{pager}',
		'emptyText'=>'We did not find any items with your search critera. Please try another search.',
		'sortableAttributes'=>array(
			'name',
			'price',
			'create_date',
			'update_date'
	    ),
	)); ?>

0

#2 User is offline   Fabrizio Caldarelli 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 282
  • Joined: 21-March 13
  • Location:Rome, Italy

Posted 30 April 2013 - 10:38 AM

In your first code, why don't you use CActiveDataProvider's pageSize (for example, 20 rows per page) ?

        $dataProvider = new CActiveDataProvider('Addon', array('criteria'=>$criteria, 'pageSize' => 20));

0

#3 User is offline   skworden 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 115
  • Joined: 14-June 12
  • Location:Virginia, USA

Posted 30 April 2013 - 11:02 AM

View PostFabrizio Caldarelli, on 30 April 2013 - 10:38 AM, said:

In your first code, why don't you use CActiveDataProvider's pageSize (for example, 20 rows per page) ?

        $dataProvider = new CActiveDataProvider('Addon', array('criteria'=>$criteria, 'pageSize' => 20));



Thanks for the reply however, that throws and error...
500 Error | Property "CActiveDataProvider.pageSize" is not defined.

I have to use this

$dataProvider->pagination->pageSize = 20;


but that doesn't work unless this is here
 $criteria->order = 'create_date DESC';


other wise it only shows 14 results even though it is set to 20.

 $criteria->order = 'create_date DESC';

that increased my queries from 7 to 13


$dataProvider->pagination->pageSize = 20;

that increased from 13 to 23


it works right if both are there but it increased my queries by 16 which doesn't work.
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