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.
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?
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
the HTML code representing a filter input (e.g. a text field, a dropdown list) that is used for this data column. This property is effective only when CGridView::enableFiltering is set true. If this property is not set, a text field will be generated as the filter input; If this property is an array, a dropdown list will be generated that uses this property value as the list options.
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.
array('enquiry_ref', 'safe', 'on'=>'search'),
$criteria->compare('enquiry_ref', $this->enquiry_ref, true);
Actually it works if I also put in:
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