CGridView filter on custom field

I have a custom field in my Model:

	public function getFullName()


		return $this->Name." ".$this->Surname;


and in the same Model I have the following code in the Search function:

	public function search()


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

		// should not be searched.

		$criteria=new CDbCriteria;


		if (isset($_GET['Applicant']['FullName']) && ($_GET['Applicant']['FullName']!=' ')) {

			$criteria->addCondition('((Name LIKE "%'.$_GET['Applicant']['FullName'].'%") OR (Surname LIKE "%'.$_GET['Applicant']['FullName'].'%"))');



In the Admin file in the View folder, I have the following definition in the CGridView columns array:





			'value' => 'CHtml::link(CHtml::encode($data["FullName"]), array("applicant/update","id"=>$data["ID"]))',



The search works fine, but there are two things that I cannot resolve:

  1. In the filter field of the column in the grid, there is always an extra space, which is why I have to check for an extra space in the if clause:

($_GET['Applicant']['FullName']!=' ')

instead of


  1. In this same filter field of the column in the grid, when I enter a search value and press enter, the field goes blank (does not remember the search value entered)

Help / suggestions appreciated :slight_smile:

read this. Although it is slightly different case logic is the same…

thank you - that put me in the right direction and got the filtering working now.