Reputation: 2104
I'm developing in Yii and im currently using Yii twitter bootstrap used to display some columns in a GridView:
Suppose I have this :
$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',
),
)
)
);
I could hide the entire column by using:
'headerHtmlOptions'=>array('style'=>'display:none'),
'htmlOptions'=>array('style'=>'display:none'),
But this is after i passed the columns parameter to the widget. I want to hide the "Value" column when its value is zero. How do i do hide or show the entire column based on its value? Thank You very much!
Upvotes: 2
Views: 6602
Reputation: 6192
Try this
array(
'name' => 'value',
'header' => 'Value',
'value' => '$data->value',
'visible' => '$data->value != 0',
'type' => 'raw',
)
Upvotes: 5