getting CGridViews filters working to calculated values

I’m trying to get calculated CGridview values as a sortable but can’t understand how to do that.

In my current situtation, the values are filtered by idInvoice, but they should be filtered by value

which is generated by countTotalPrice function. The values are correctly printed, but neither filter or sort function doesn’t work for them.

How to make filter to work by counted values?

This is how my files looks like:

CGridView




...

		array(

				'sortable'=>true,

				'name'=>'idInvoice',			

				'value'=>'Yii::app()->storage->countTotalPrice($data)',

				'header'=>'Summa'

		),	

...



countTotalPriceFunction




	public function countTotalPrice($data)

	{

		if(!isset($data->invoiceDetails))

			return -0;

		$vat = $data->invoiceDetails->VAT;

		$products = Product::model()->findAll('idInvoiceDetails =:id', array(':id'=>$data->idInvoice));

		

		$totalCount = 0;

		//$totalCount = $data->idInvoice;

		if(isset($products) && $products!= false)

		{

			foreach($products as $p)

			{

				$totalCount += $p->units * $p->unitPriceNoVAT;		

			}

		}


		

		return 0.01*(round(($totalCount * (100 + $vat)/100)*100));

	}



(model) Invoice.php




...

	public function search($condition = "")

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->with = array('person', 'invoiceDetails');


		$criteria->compare('person.company', $this->idPerson,true);

		

		$criteria->compare('person.name', $this->person_name,true);




		$criteria->compare('invoiceDetails.idInvoiceDetails', $this->idInvoice,true);


		if($condition != "")

			$criteria->condition = $condition;

		

		

		$criteria->compare('pdfUrl',$this->pdfUrl,true);


		$criteria->compare('state',$this->state,true);


		$criteria->compare('reason',$this->reason,true);


		$criteria->compare('paid',$this->paid,true);


		$criteria->compare('uploadDate',$this->uploadDate,true);




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

			'criteria'=>$criteria,

		    'sort'=>array

			(

				'defaultOrder'=>'uploadDate DESC',

			),			

		));

	}

...



Thanks in advance, if someone can respond this hard question!