我正在开发Yii,我目前正在使用Yii twitter bootstrap用于在GridView中显示一些列:
假设我有这个:
$this->widget('bootstrap.widgets.TbGridView', array(
'id'=>'gridview',
'dataProvider'=>new CArrayDataProvider($model),
'template'=>"{items}",
'type'=>'bordered',
'columns'=>array(
array(
'header' => 'Entries',
'value' => '$data->entry_name'
),
array(
'name' => 'value',
'header' => 'Value',
'value'=>function($data){
//if $data->value is zero then hide the "Value" column
if($data->value == 0){
//do something to hide the column here
}
//otherwise return a label to display the value inside
return CHtml::label($data->value,FALSE,array('id'=>'label'));
},
'type'=>'raw',
),
)
)
);
Run Code Online (Sandbox Code Playgroud)
我可以使用以下方法隐藏整个列:
'headerHtmlOptions'=>array('style'=>'display:none'),
'htmlOptions'=>array('style'=>'display:none'),
Run Code Online (Sandbox Code Playgroud)
但这是在我将columns参数传递给小部件之后.我希望在值为零时隐藏"值"列.如何根据其值隐藏或显示整个列?非常感谢你!