Search in Grid View ?

Hi… :)

i have problem when search data in GridView, i want to filter customer field(firstname & lastname).

this search code in customer model




public function search()

	{


		$criteria=new CDbCriteria;

                             

                $criteria->condition = "status>=:sts";

                $criteria->params = array(':sts'=>0);


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

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


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

			'criteria'=>$criteria,

		));

	}



and GridView code:




$this->widget('zii.widgets.grid.CGridView', array(

    'id'=>'gridcust',

    'filter'=>$model,

    'dataProvider'=>$model->search(),

    'columns'=>array(            

        array(

            'header'=>Yii::t('MGlobal', 'tbl.custname'),

            'value'=>'$data[firstname]." ".$data[lastname]',

            'name'=>'firstname',

        ),



so my questions are :

  • how to search firstname and lastname within one column

  • when i put value in textbox and press enter filter does not work.

(i want to filter firstname eka but data not changed).

I’ve tried to find a way, but still not successful.

thanks

What you need is

1 - Create a variable in your model class

2 - Explode the based on space or any other mean for first name and last name

3 - use these values in compare

4 - Define custom sorting to enable the sorting based on new defined variable

if you need example, then follow the link below

http://www.yiiframework.com/forum/index.php?/topic/19913-cgridview-with-multiple-models/page__view__findpost__p__98809

thank for your replay, but still can not display.

i tried like this :

model:




class TCustomer extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @return TCustomer the static model class

	 */

	 

	public $_custname = null;


public function getCustName()

	{

		return $this->_custname;

		

	}

   public function setCustName($value)

   {

        $this->_countryName = $value;

   }


public function search()

	{

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

		// should not be searched.


		$criteria=new CDbCriteria;

		

		$this->_custname = $this->firstname . ' ' . $this->lastname;






and in gridview i call:




 array(

            'header'=>'Customer Name',

            'value'=>'$data[CustName]',

        ),



whether the way I am doing is correct. if not please corrections.

thanks

I think, the issue is here


              $this->_custname = $this->firstname . ' ' . $this->lastname;

You need to use it for compare but currently, you are assigning it which is not correct.