Search Functinality With Model

in view file my code is

<?php Yii::import(‘zii.widgets.grid.CGridColumn’);

class CounterColumn extends CGridColumn


{


	private &#036;i = 1;


	public function init()


	{


		&#036;pager=&#036;this-&gt;grid-&gt;dataProvider-&gt;pagination;


		&#036;this-&gt;i=0;


	}


	public function renderDataCellContent(&#036;row, &#036;data) // &#036;row number is ignored


	{ 


		&#036;this-&gt;i++;


		echo &quot;&lt;label class='sel' for='check_&quot;.&#036;this-&gt;i.&quot;'&gt;&amp;nbsp;&lt;/label&gt;&quot;;


	}


}





&#036;dataProvider=new CActiveDataProvider('Lead', array('criteria'=&gt;array(


 	'condition'=&gt;'status &#33;= &quot;Allocated&quot; AND isDuplicate = &quot;no&quot; AND isJunk = &quot;no&quot; ',


    'order'=&gt;'leadId DESC',


    )));


 &#036;alert=&quot;Are you sure you want to Change Status? &quot;;


&#036;this-&gt;widget('zii.widgets.grid.CGridView', array(


 'id'=&gt;'acc-payment-recei-grid',


'htmlOptions' =&gt; array('class' =&gt; 'items'),


'ajaxUpdate'=&gt;false,


'enableSorting'=&gt;true,


'enablePagination' =&gt; true,


'pager' =&gt; array(


		'header' =&gt; '&amp;nbsp;',


		'prevPageLabel' =&gt; 'Prev',


		'nextPageLabel' =&gt; 'Next',


		),


'dataProvider'=&gt;&#036;dataProvider,


'columns'=&gt;array(


array(


        'header'=&gt;'',


        'class'=&gt;'CounterColumn',


		'htmlOptions'=&gt;array('class'=&gt;'hideheader'),


		),


array(


        'class' =&gt; 'CCheckBoxColumn',


		'id'=&gt;'check',


        'selectableRows' =&gt; 2,


        'checkBoxHtmlOptions' =&gt; array(


		'id'=&gt;'check',


		'name' =&gt; 'userids[]',


		'class'=&gt;'cbox',


		'rel'=&gt;'cbox',


        ),


        'value'=&gt;'&#036;data-&gt;leadId',


		'htmlOptions'=&gt;array('width'=&gt;'10px'),


     ),		


    array(            // display 'create_time' using an expression


        'name'=&gt;'Mobile',


        'value'=&gt;'@&#036;data-&gt;mobile',


		'sortable'=&gt;TRUE,


    ),


	 array(            // display 'create_time' using an expression


        'name'=&gt;'Name',


		'value'=&gt;'@&#036;data-&gt;name',


        


		'sortable'=&gt;TRUE,


    ),


	array(            // display 'create_time' using an expression


        'name'=&gt;'Email',


		'value'=&gt;'@&#036;data-&gt;email',


        


		'sortable'=&gt;TRUE,


    ),


	 array(            // display 'create_time' using an expression


        'name'=&gt;'Lead Stage',


		'value'=&gt;'@&#036;data-&gt;leadStageDetails-&gt;leadStage',


        


		'sortable'=&gt;TRUE,


    ),


	 array(            // display 'create_time' using an expression


        'name'=&gt;'Date &amp;amp; Time',


		'value'=&gt;'date(&quot;d/m/y h:i A&quot;,@&#036;data-&gt;createdOn)',


        


		'sortable'=&gt;TRUE,


    ),


	 array(            // display 'create_time' using an expression


        'name'=&gt;'UTM Code',


		'value'=&gt;'@&#036;data-&gt;leadSourceDetails-&gt;leadSourceCode',


        


		'sortable'=&gt;TRUE,


    ),		 


	array(            // display 'create_time' using an expression


        'name'=&gt;'History',


		'type'=&gt;'raw',


		'value'=&gt;'CHtml::link(&quot;Details&quot;,array(&quot;leads/leads_details&quot;,&quot;leadId&quot;=&gt;&#036;data-&gt;leadId))',


		'sortable'=&gt;TRUE,


    ),


    array(            // display a column with &quot;view&quot;, &quot;update&quot; and &quot;delete&quot; buttons


	 'header'=&gt;'Action',


	 'htmlOptions'=&gt;array('style'=&gt;'width: 80px',),


        'class'=&gt;'CButtonColumn',


		'template' =&gt; '&lt;table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; class=&quot;iconitem&quot;&gt;


              &lt;tr&gt;


			  	&lt;td&gt;'.(&#036;moduleAccessArray['write']==&quot;yes&quot;?&quot;{edit}&quot;:&quot;NA&quot;).'&lt;/td&gt;


			  	&lt;td class=&quot;nobg&quot;&gt;'.(&#036;moduleAccessArray['write']==&quot;yes&quot;?&quot;{view}&quot;:&quot;NA&quot;).'&lt;/td&gt;                   


              &lt;/tr&gt;


              &lt;/table&gt;',


		 'buttons' =&gt; array(


		 	'Active' =&gt;array(


                'url' =&gt; 'Yii::app()-&gt;controller-&gt;createUrl(&quot;ChangeRoleStatus&quot;,array(&quot;leadId&quot;=&gt;&#036;data-&gt;leadId,&quot;status&quot;=&gt;&#036;data-&gt;status))',


				'imageUrl'=&gt;Yii::app()-&gt;baseUrl.'/images/active.png',


				'label' =&gt; @&#036;model-&gt;status,


				


				'visible'=&gt;'(&#036;data-&gt;status==&quot;Active&quot;)?1:0',


                'options' =&gt; array(// this is the 'html' array but we specify the 'ajax' element


                    'confirm' =&gt; &#036;alert,


                    'class' =&gt; 'grid_action_set1',


					


                   'click'=&gt;&quot;function(){


                                &#036;.ajax({


                                    type:'POST',


                                    url:'',


                                    success:function(data) {


                                          &#036;('#AjFlash').html(data.status).fadeIn().animate({opacity: 1.0}, 3000).fadeOut('slow');





                                          &#036;.fn.yiiGridView.update('user-grid');


                                    }


                                })


                                return false;


                          }


                 &quot;,


                ),


            ),


			'Deactive' =&gt;array(


                'url' =&gt; 'Yii::app()-&gt;controller-&gt;createUrl(&quot;ChangeRoleStatus&quot;,array(&quot;id&quot;=&gt;&#036;data-&gt;leadId,&quot;status&quot;=&gt;&#036;data-&gt;status?&#036;data-&gt;status:&quot;Inactive&quot;))',


				'imageUrl'=&gt;Yii::app()-&gt;baseUrl.'/images/dactivate_icon.png',


				'label' =&gt; @&#036;model-&gt;status,


				


				'visible'=&gt;'(&#036;data-&gt;status==&quot;Inactive&quot; or &#036;data-&gt;status==&quot;&quot;)?1:0',


                'options' =&gt; array(// this is the 'html' array but we specify the 'ajax' element


                    'confirm' =&gt; &#036;alert,





                    'class' =&gt; 'grid_action_set1',


					


                   'click'=&gt;&quot;function(){


                                &#036;.ajax({


                                    type:'POST',


                                    url:'',


                                    success:function(data) {


                                          &#036;('#AjFlash').html(data.status).fadeIn().animate({opacity: 1.0}, 3000).fadeOut('slow');





                                          &#036;.fn.yiiGridView.update('user-grid');


                                    }


                                })


                                return false;


                          }


                 &quot;,


                ),


            ),


			'edit' =&gt; array(


                'url' =&gt; 'Yii::app()-&gt;controller-&gt;createUrl(&quot;leads/create_lead&quot;,array(&quot;leadId&quot;=&gt;&#036;data-&gt;leadId))',


				'imageUrl'=&gt;Yii::app()-&gt;request-&gt;baseUrl.'/images/edit_icon.png', 


			


			),


			'view' =&gt; array(


                'url' =&gt; 'Yii::app()-&gt;controller-&gt;createUrl(&quot;leads/lead_details&quot;,array(&quot;leadId&quot;=&gt;&#036;data-&gt;leadId))',


				'imageUrl'=&gt;Yii::app()-&gt;request-&gt;baseUrl.'/images/view_icon.png', 


			


			),


       ),





    ),


	


),

));

?>

in controller

public function actionlead_list()

{


	// renders the view file 'protected/views/site/index.php'


	// using the default layout 'protected/views/layouts/main.php'


	&#036;model	=	new Lead();


	&#036;model	=	Lead::model()-&gt;findAll(&quot;status = 'Active'&quot;);


	&#036;this-&gt;render('lead_list',array('model'=&gt;&#036;model));


}

in model

public function relations()


{


	// NOTE: you may need to adjust the relation name and the related


	// class name for the relations automatically generated below.


	return array(		


	'stateDetails' =&gt; array(self::BELONGS_TO, 'state', 'stateId'),


	'cityDetails' =&gt; array(self::BELONGS_TO, 'city', 'cityId'),


	'customerTypeDetails' =&gt; array(self::BELONGS_TO, 'customerTypeMaster', 'customerTypeId'),


	'productDetails' =&gt; array(self::BELONGS_TO, 'productMaster', 'productId'),


	'planTypeDetails' =&gt; array(self::BELONGS_TO, 'planTypeMaster', 'planTypeId'),


	'policyTypeDetails' =&gt; array(self::BELONGS_TO, 'policyTypeMaster', 'policyTypeId'),


	'campaignDetails' =&gt; array(self::BELONGS_TO, 'campaign', 'campaignId'),


	'leadSourceDetails' =&gt; array(self::BELONGS_TO, 'leadSourceMaster', 'leadSourceId'),


	'leadStageDetails' =&gt; array(self::BELONGS_TO, 'leadStageMaster', 'leadStageId'),


	'leadStatusDetails' =&gt; array(self::BELONGS_TO, 'leadStatus', 'leadStatusId'),


	);


}





/**


 * @return array customized attribute labels (name=&gt;label)


 */


public function attributeLabels()


{


	return array(


		'leadId' =&gt; 'Lead',


		'email' =&gt; 'Email',


		'emailOptOut' =&gt; 'Email Opt Out',


		'mobile' =&gt; 'Mobile',


		'mobileOptOut' =&gt; 'Mobile Opt Out',


		'status' =&gt; 'Status',


		'createdBy' =&gt; 'Created By',


		'createdOn' =&gt; 'Created On',


		'updatedBy' =&gt; 'Updated By',


		'updatedOn' =&gt; 'Updated On',


	);


}





/**


 * Retrieves a list of models based on the current search/filter conditions.


 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.


 */


public function search()


{


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


	// should not be searched.





	&#036;criteria=new CDbCriteria;





	&#036;criteria-&gt;compare('leadId',&#036;this-&gt;leadId,true);


	&#036;criteria-&gt;compare('email',&#036;this-&gt;email,true);


	&#036;criteria-&gt;compare('emailOptOut',&#036;this-&gt;emailOptOut,true);


	&#036;criteria-&gt;compare('mobile',&#036;this-&gt;mobile,true);


	&#036;criteria-&gt;compare('mobileOptOut',&#036;this-&gt;mobileOptOut,true);


	&#036;criteria-&gt;compare('status',&#036;this-&gt;status,true);


	&#036;criteria-&gt;compare('createdOn',&#036;this-&gt;createdOn,true);


	&#036;criteria-&gt;compare('createdBy',&#036;this-&gt;createdBy,true);


	&#036;criteria-&gt;compare('updatedOn',&#036;this-&gt;updatedOn,true);


	&#036;criteria-&gt;compare('updatedBy',&#036;this-&gt;updatedBy,true);





	return new CActiveDataProvider(&#036;this, array(


		'criteria'=&gt;&#036;criteria,


	));


}

how search with particular data

I think you should make different component,for Countercoloumn,so there willl be no need for include that code in every view file,just copy your code of class in other file,save it in components with name CounterColoumn.php

& use it,as,you are using.

For your search problem,

according to me,you should include in controller like,

$model->unsetAttributes();

if(isset($_GET[‘Lead’]))

$model->attributes=$_GET[‘Lead’];

Change it,according to youe need.God luck!

[color="#556B2F"]/* Moved from "Bug Discussions" to "General Discussion for Yii 1.1.x" */[/color]