CGridView paging not working

I have a model which have query with join in CDbCriteria like this


public function cpu($filter)

{

	$criteria = new CDbCriteria;

	$criteria->alias = 'op';

	$criteria->select = "op.*, oc.trainingtype_c";

	$criteria->join = 'join opportunities_cstm oc on op.id=oc.id_c ';

	$criteria->join .= 'join users u on op.assigned_user_id=u.id ';

	$criteria->condition = "u.deleted=0 and op.deleted=0 and not op.assigned_user_id is null ";

	$criteria->order = 'op.assigned_user_id, oc.expectdate_c';

	

	if ($filter['department']!='Nasional') {

		if ($filter['department']=='DKI (All)') 

			$criteria->condition .= "and u.department like 'DKI%'";

		else if ($filter['department']=='NDD (All)') 

			$criteria->condition .= "and u.department like 'NDD%'";

		else 

			$criteria->condition .= "and u.department like '".$filter['department']."'";

	}

	if ($filter['training_type']!='Semua') {

		$criteria->condition .= "and oc.trainingtype_c like '".$filter['training_type']."'";

	}

	if ($filter['account_name']!='') {

		$criteria->condition .= "and op.id in ( select opportunity_id 

			from accounts t1 join accounts_opportunities t2 on t1.id=t2.account_id

			where t1.name like '%".trim($filter['account_name'])."%' )";

	}


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

		'criteria'=>$criteria,

		'pagination'=>array(

			'pageSize'=> Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']),

		),

	));

}

and a view to render it like this,


$this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'cpu-grid',

	'dataProvider'=>$model->cpu($filter),

	'filter'=>$model,

	'columns'=>$column,

));

it’s working fin for first page, but gives empty data for second and other pages.

did I miss something?

regards,

NH

in CGridView

Paging in CGridView use Ajax, and $filter variable not include in so

use property AfterAjaxUpdate for update $filter variable

you can read manual CGridView, how to user AfterAjaxUpdate

This link is example how to use AfterAjaxUpdate, this solve myproblem

http://www.yiiframework.com/forum/index.php?/topic/17478-solved-highslide-and-fancybox-not-working-in-cgridview-if-page-1/page__p__86544__hl__high+lide+fancybox#entry86544

thanks for your reply.

$filter is actually a model, and i cant find a way to pass it as argument using to "cpu" function using javascript

I solved it using session.

hello can u share to us how to fix it, because I have problem same, cgridview in page 1 work, but while I click page 2 etc… it doesn’t work, and I use in jdialog