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);



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




and GridView code:

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






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

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



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.


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

thank for your replay, but still can not display.

i tried like this :


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:


            'header'=>'Customer Name',



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


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.