Hello,
Apologies if this is an easy answer. I’ve done some digging and couldn’t figure out how to do it. I’ve added a dropdown list in my search form that filters CGridView, but I’m not able to add a null value to the dropdown. What I’d like to have happen is that when a user selects the null option it clears the filter in the table.
2 Questions
-
How do I add a null value to the dropdown?
-
If the null option is selected will it clear the filter automatically or should I add some JQuery to clear the value in the filter?
Thanks for your help.
Search form
<div class="row">
<?php echo $form->label($model,'project'); ?>
<?php echo $form->dropDownList($model,'project',$model->getProjectOptions()); ?>
</div>
Model function for dropdown data
public function getProjectOptions()
{
$user=Users::model()->findByAttributes(array('username'=>Yii::app()->user->id));
$accountnumber = $user->accountnumber;
$projectsArray = CHtml::listData(Projects::model()->findAllByAttributes(array('accountnumber'=> $accountnumber)), 'internalid', 'projectname');
return $projectsArray;
}