CLinkColumn Filter

I have an enquiry ref field in my Model, this is displayed in CGridView. I wanted the field to be clickable to view the record, so I implemented it in a CLinkColumn. This is all good now, except the filter is not available, meaning I can no longer do a quick-search for a record based on the reference.




	'header'=>'Enquiry Ref',

	'urlExpression'=>'array("enquiry/view", "id"=>$data->id)',


CLinkColumn doesn’t have a filter property unfortunately, so is there any other way I can make the text clickable and retain the filter functionality?

Anyone able to advise?

You can use a CDataColumn with type=>raw and value=CHtml::link($data->enquiry_ref, array("enquiry/view", "id"=>$data->id));

Cheers man, I just tried that but it still won’t give me a filter. I set the ‘filter’ property to ‘$data->enquiry_ref’.

‘filter’ should be a CHtml::textBox or something like that, according do documentation

Anyway I guess that you can just set the ‘name’ properto to the attribute of the model that you want to filter, and it will be generate the textbox by himself

Just added in the ‘name’ property, and yes the filter is displayed but does not work:



	'value'=>'CHtml::link($data->enquiry_ref, array("enquiry/view", "id"=>$data->id));',




You can type in the box, but as soon as you tab away the text is cleared and it does not actually perform any search.

This is a problem of model.

The field should be ‘safe’ ‘on’=>‘search’ and in the search function you have to implement the search.

It is :(

array('enquiry_ref', 'safe', 'on'=>'search'),


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

Actually it works if I also put in:

array('enquiry_ref', 'safe'),

That’s weird, I would have thought the “‘safe’, ‘on’=>‘search’” rule would be sufficent.

It should work with on=>save, are you sure you create the model new Model(‘search’).

This should set the proper scenario and all should work fine