Help Needed With Filter In Cgridview

Hi,

I am having a weird behaviour with 2 identical filters in a cgridview. One is working while the other is not. Can anyone please help me?







array('name'=>'resident','value'=>'$data->resident? "Yes" : "No"','headerHtmlOptions'=>array('width'=>'50'),'filter'=>array('1'=>'Yes','0'=>'No')), //this one works


array('name'=>'closed','value'=>'$data->closed? "Closed" : "Open"','headerHtmlOptions'=>array('width'=>'50'),'filter'=>array('1'=>'Closed','0'=>'Open')),//this one does not work




Both attributes (resident and closed) are boolean and are stored as tinyint(1) in mysql tables. The filter for closed attribute is not working. I must surely be missing something obvious but I do not see what…

Thanks

check if ‘closed’ attribute is added to ‘safe’ attributes in ‘search’ scope (rules() method in object) and also if it is used in search() method when creating search criteria

It depends what you mean by "does not work". Are all records being returned regardless of whether you select Open or Closed? Is the filter being reset when the grid reloads? Is an error being returned? Is no grid refresh taking place?

Can you post your full model class? I suspect there’s either a problem with the search() method or model rules, or an issue with default values.

EDIT:

Ninja’d again by my arch nemesis, Redguy… <_<

My kung-fu is stronger that yours ;)

Hi Redguy,

I knew it was something obvious that I was missing. It works absolutely fine when I followed your 2 instructions. I had forgotten that I had added this attribute after having built my model and did not do the necessary updates to my model.

Thank you lotssssss :D

Hi Keith,

You are right. I had forgotten to update the search() method after having added the ‘closed’ attribute when the model was already built. The attribute was also not added to the ‘safe’ attributes for search method.

Thank you so much.

This Yii community is really wonderful :)