In a gridview, if I set the "filter" property of a column as an array, the filter will be rendered as a dropdown list by default, with the first option is an empty string meaning no filtering. How can I set to render the first option as "All" instead of an empty string?
I think that is not possible with a simple array, you have to do on your own:
'filter'->CHtml::activeDropDownList($model, 'attribute', array(['']), array('prompt'=>'All'));
Do you think this should be submitted as an issue at the tracker? BTW, what’s the difference between “empty” and “prompt” in the $htmlOptions argument?
Check the documentation for activeDropDownList - http://yiiframework.com/doc/api/1.1/CHtml#activeDropDownList-detail
Yes, I’ve read the docs. It seems to me that the only difference is that “the ‘empty’ option can also be an array of value-label pairs. Each pair will be used to render a list option at the beginning.”
If a string is given, they generate the same HTML. Seems that we can always use ‘empty’
Hello,
I appreciate this post, following are my codes that fixed my scenario:
array(
'header'=>'Schedule',
'name'=>'scheduledExam',
'filter'=>CHtml::activeDropDownList($model, 'scheduledExam', array(date("Y-m-d")=>'Today'), array('prompt'=>'All')),
'type'=>'raw',
'value'=>'displaySchedule($data)',
'htmlOptions'=>array('style'=>'text-align: left; padding-left: 0.5em'),
'headerHtmlOptions'=>array('width'=>'125px'),
),