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:











	public function countTotalPrice($data)



			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('', $this->idPerson,true);


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

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

		if($condition != "")

			$criteria->condition = $condition;








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




				'defaultOrder'=>'uploadDate DESC',





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