Extend Filter Length

Hi there,

I’m having a database with a year format (4 integers), which I want to view in my CGridView.

The problem is that the filter of CGridView for the year is limited by 4 characters. So I can not say something like ">=2000".

Is this possible?

Thank you in advance!

Reinier

Dear Friend

Would you please check the following.

Try to create column like this




array(

	'name'=>'year', //your attribute

	'filterHtmlOptions'=>array('width'=>'160px'), //customize by adjusting pixels.

		),



Regards.

Dear seenivasan,

Thanks for your quick reply. My problem is the maxLength set in the Model.

I want the user to have a restriction of 4 characters when inserting the year,

but in the CGridview I want to overwrite the maxLength and have a possibility to have 6 characters (>=yyyy)

I’ve tried the filterHtmlOptions, but this only affects the td row where the filter input is in.

Is there a way how I can modificate the maxLength in the admin part of my Model,

or should I just set the maxLength in the Model to 6 and in the _form.php to 4 (via Html options?)

Thanks in advance,

Reinier

Dear Friend

Sorry about that.

I completely failed to grasp your exact requirement.

I hope the following would help.

Try to create a column like this in your admin.php.




array(

	'name'=>'year', //your attribute 

	'filter'=>CHtml::activeTextField($model,'year',array('maxlength'=>6)),

	),



Regards.

I think this is exactly the case where the ‘scenario’ of the validation rules works. I mean you can define different rules for create/update (where max length should be 4) and search (where it can be 6).

Isn’t enough to set ‘year’ as ‘safe’ in ‘search’ scenario?

Yes you are absolutely correct.

That looks pretty simple, if we apply scenarios.

Thanks my Friend.

Gentleman, thank you for your replies!

Unfortunately the safe mode wasn’t enough. (This was allready set).

Now I have to following codelines:




rules(){

return array(

...

array('jaar_inschrijving', 'length', 'min'=>4, 'max'=>4, 'on'=>'register'),

array('jaar_inschrijving', 'length', 'min'=>4, 'max'=>6, 'on'=>'search'),

array('..., jaar_inschrijving, ...', 'safe', 'on'=>'search'),



And that works ;) So thank you for your reactions, this was something I did not have discovered earlier.

Have a great day!