I found that if I use custom "select", it's not respected and calculation of the pages is not correct in some cases.
If we have:
$criteria->select = 'SUM(some_column), ..'
This will affect the rows number and since the "select" is not used to calculate totalItemCount, pages and items number will mismatch.
The solution is to overwrite totalItemCount:
public function search()
{
$criteria=new CDbCriteria;
$criteria->select = 'SUM(col)';
$dataProvider = new CActiveDataProvider($this, array('criteria'=>$criteria));
$dataProvider->setTotalItemCount(count($this->findAll($criteria)));
return $dataProvider;
}
Yii Forum topic