Modify cgridview filter

Hi all,

I have a table called product_stock. It has the fields product_id, product_stock, stock_date.

In my cgrid view, i want to enter the product_name and i want to list only the latest stock record from the db.

Ex. if my table has the contents

product_id product_stock stock_date

1 [color="#8B0000"]45 units [/color][ 2011/05/01

1 [color="#8B0000"] 50 units [/color][ 2011/05/10

1 [color="#8B0000"] 60 units [/color][ 2011/05/15

2 [color="#8B0000"] 40 units [/color][ 2011/05/17

2 [color="#8B0000"] 35 units [/color][ 2011/05/20

When i filter product_id 1, only 60 units 2011/05/15 should be filtered.

How do i go about this?Please help!!!!!


Change the generation of CActiveDataProvider:

new CActiveDataProvider('ProductStock', array(



Hi zaccaria,

I tried what u asked but it didnt work.

Here is my search function in the model.

public function search1()


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

		// should not be searched.<br />

		$criteria=new CDbCriteria;

		 $criteria->condition = "prod_update_id in (select MAX(prod_update_id) from product_update where product_id=:product_id)";        


$criteria->params = array(":product_id" =>$this->product_id);  //i think the problem is in binding the param



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




I think the problem is that the product_id is not fetched.

Please help me figure this out.


I fixed the error. There is nothing wrong with my search function which i mentioned before, the problem occurred because the product ids which i was enterring to search was in a multi select dropdown. I changed it to a normal dropdown and the search works fine.

But i want it to be a multi select dropdown. What changes would i have to make to my search function to make it work?