Help With Filter/search In Cgridview

Hi,

I have a column name called status. In status there are options like active and inactive.

my problem is that when i seach for or select active, both active and inactive rows are displayed.

I want if i search for active only active rows should be displayed and vice-versa

Sorry if this has being asked earlier. i have searched but havent found solution on it.

Regards

sanjay

Hi,

Post your Cgridview code, search method and controller action code

Hi,

Thanks for your reply find below the code.




public function actionAdmin()

	{

		$model=new Leads('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['Leads']))

			$model->attributes=$_GET['Leads'];


		$this->render('admin',array(

			'model'=>$model,

		));

	}



view/admin.php




array( 

        'name' => 'lead_status', 

        'filter' => $model->getLeadStatusOptions(), 

		),



model/leads.php





class Leads extends CActiveRecord

{


	        const STATUS_ACTIVE='Active';

		const STATUS_BLOCK='Block';

		const STATUS_INACTIVE='Inactive';

		const STATUS_DELETED='Deleted';


public function getStatusOptions()

		{

			return array(

				self::STATUS_ACTIVE=>'Active',

				self::STATUS_BLOCK=>'Block',

				self::STATUS_INACTIVE=>'Inactive',

				self::STATUS_DELETED=>'Deleted',

				);

		}	



I am assuming you use CGridview and ‘dataProvider’ => $model->search(),

could you post the search method too ?

I have not modified any search method, It is the default one which comes with yii.

Kindly let me what code you are exactly looking for.

what is the type of column status ?

Pleas post both search and rules methods,

I can’t help you if you do not give us more details :)

Hi,

Sorry for the late reply as i was not feeling well so i was away from yii.

I am still new to yii, kindly let me know which file i should provide you so that you can get the required details.

Try something like this…




'filter'=>CHtml::dropDownList('Leads[lead_status]','',Leads::model()->statusOptions,array('empty'=>'')),



And if you have still have same problem with searching "Active" and "Inactive", just use integer type insteed string…





class Leads extends CActiveRecord

{


                const STATUS_ACTIVE=0;

                const STATUS_BLOCK=1;

                const STATUS_INACTIVE=2;

                const STATUS_DELETED=3;


public function getStatusOptions()

                {

                        return array(

                                self::STATUS_ACTIVE=>'Active',

                                self::STATUS_BLOCK=>'Block',

                                self::STATUS_INACTIVE=>'Inactive',

                                self::STATUS_DELETED=>'Deleted',

                                );

                }      



Don’t forget to convert string to integer in your ‘lead_status’ database column.

Hi,

I tried both none of them worked,but after changing the string to integer in my database column that column is now having the value of zero(0) instead of active and other options, even after reverting the column to string it still contains the value of zero.

Thanks i was testing in test environment.

But the problem still resides.