[SOLVED] CGridView pages are not calculated correctly if I have "select" criteria


I have grid view with custom select like:

$criteria->select = ‘SUM(…), …’

It works good, but seems that paging calculation doesn’t respect this select, so without SUM() I have many pages while there are only 2 real rows in set.

From MySQL query logs I can see that this custom select is just missing.

Can someone help me with this?

Am I wrong with something or this is an issue with the AR?


PS - using yii-1.1.10.r3566

public function search()


	$criteria=new CDbCriteria;

	$criteria->select = 'sum(someField), …';

	$criteria->group = 'tableId';


	$dp = new CActiveDataProvider($this, array('criteria'=>$criteria));


	return $dp;


This come of course at the expense of one additional query (findAll), but it’s the only viable solution I’ve found that works even with multiple pages.

Very cool workaround, thanks a lot! :)