Underscore "_" Doesnt Work In Cgridview Search

Hello everyone.

i have a problem in CGridView with filters.

I have some columns that have data with underscores, like “125_120”. And when i put the underscore in filters, the framework can’t find anything… Seems to be a problem with encoding.

Here is the example:

3608

Capture.PNG

3609

Capture2.PNG

I will appreciate any help :)

bump to the top…

The actual filtering is done in the model->search() method… how are you using that value there?

Im doing as Yii framework generates crude…

My admin.php (where there is the CGridView)




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

	'id'=>'fw-status-translate-grid',

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

	'filter'=>$model,

....

),);



What I asked is what are you doing with the entered value in the $model->search() method ?

I didnt understand your question since i didn’t invent anything…

btw here is the code:




public function search()

	{

		$criteria=new CDbCriteria;


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

		

		if(strpos($this->NCODE, '%') === false)

			$criteria->compare('LOWER(NCODE)', strtolower($this->NCODE), false);

		else

			$criteria->compare('LOWER(NCODE)', strtolower(str_replace('%', '', $this->NCODE)), true);

			

		$criteria->compare('LOWER(NDESC)', strtolower($this->NDESC), true);

		$criteria->compare('LOWER(ECODE)', strtolower($this->ECODE), false);

		$criteria->compare('LOWER(EDESC)', strtolower($this->EDESC), true);

		$criteria->compare('LOWER(ACCAO)', strtolower($this->ACCAO), true);

		$criteria->compare('LOWER(RESPONSAVEL)', strtolower($this->RESPONSAVEL), true);

		$criteria->compare('LOWER(ACCAORECURSO)', strtolower($this->ACCAORECURSO), true);

		$criteria->compare('LOWER(RESPONSAVELRECURSO)', strtolower($this->RESPONSAVELRECURSO), true);

		$criteria->compare('LOWER(EVENTSTATUS)', strtolower($this->EVENTSTATUS), true);

		$criteria->compare('LOWER(SERVICE)', strtolower($this->SERVICE), true);

		$criteria->compare('LOWER(OPERATION)', strtolower($this->OPERATION), true);

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


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

			'pagination'=>array(

				'pageSize'=>30

			),

		));

	}



Just added some validation in generated model from crude (added strtolower validations).

My actionAdmin from controller is exactly the same:




public function actionAdmin()

	{

		$model=new FW_STATUS_TRANSLATE('search');

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

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

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


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

			'model'=>$model,

		));

	}



Thank you for your time :)

So… the $model-search() method is the one that makes the database search and returns the filtered data when you enter something on the filter input field.

The method you posted above is from the model that is shown on the grid (FW_STATUS_TRANSLATE)?

On your first post, on the pictures, the column name is "Val Dest"… what is the variable (field name) for that column?

Sorry Maurizio, I mistake the models… From the pictures the correct model is EAI_TMAPEAMENTO

Here is the code of $model->search():




public function search()

	{

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

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('ID_SEQ',$this->ID_SEQ);

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

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

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

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

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

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


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

			'sort'=>array(

				'defaultOrder'=>'ID_SEQ, ENTIDADE, ATRIBUTO ASC',

			),

			'pagination'=>array(

				'pageSize'=>10

			),

		));

	}



The code is exactly as the generated from yii. The action in controller is the same as above but for EAI_TMAPEAMENTO :)

So the actual line that process that field is this one


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

from the BIG filed names I presume you are using MSSQL or ORACLE… From what I know in MSSQL the underscore is a wildchar (probably the same in oracle) , not in mysql that’s why in mysql this works.

If that is the case you need to escape the underscore characters so to actually search for a literal underscore.

Yes my DB is oracle.

Found the solution for "escape" characters in this guide

Oracle Escape Characters

Thank you for your time Maurizio :)