Yii Framework Forum: CLinkColumn Filter - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CLinkColumn Filter Rate Topic: -----

#1 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,037
  • Joined: 30-October 09
  • Location:UK

Posted 18 July 2010 - 11:48 AM

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.

array(
	'class'=>'CLinkColumn',
	'labelExpression'=>'$data->enquiry_ref',
	'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?
0

#2 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,037
  • Joined: 30-October 09
  • Location:UK

Posted 19 July 2010 - 04:05 AM

Anyone able to advise?
0

#3 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 19 July 2010 - 04:40 AM

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

#4 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,037
  • Joined: 30-October 09
  • Location:UK

Posted 19 July 2010 - 04:49 AM

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

#5 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 19 July 2010 - 05:20 AM

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

Quote

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
1

#6 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,037
  • Joined: 30-October 09
  • Location:UK

Posted 19 July 2010 - 05:36 AM

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

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


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.
1

#7 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 19 July 2010 - 05:40 AM

This is a problem of model.

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

#8 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,037
  • Joined: 30-October 09
  • Location:UK

Posted 19 July 2010 - 05:46 AM

View Postzaccaria, on 19 July 2010 - 05:40 AM, said:

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

0

#9 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,037
  • Joined: 30-October 09
  • Location:UK

Posted 19 July 2010 - 06:03 AM

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.
1

#10 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 19 July 2010 - 06:54 AM

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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users