Default value in Filter

Good day.

Anyone have an idea on how to add default value in filter field?


I want to add 3833- a default value for voucher no

here is the code:

<?php $grid = $this->widget('zii.widgets.grid.CGridView', array(












Please change actionSearch in your model like this…


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



If you want default filter please use following code [but its not right]


	$this->voucher_no = '3833';

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

The above solution would search the default value in case the user did not input anything…

If you want a default value to be displayed to the user so that he can change it or add some criteria… in your model… before rendering the view add the desired value to the model field… like

$model = new yourmodel();



This works great!

Thanks mdomba!


This works if the default filter is set directly on table records, but what about if I want to set a default filter on a related record value ?? I tried to do it like :

$model->relatedModel->TheAttributeIWantCheck = ‘’;

but I have an "Indirect modification of overloaded property" exception