2

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!

3
  • 3
    The column as a whole has many values, not just one. Can you be more specific? Commented Oct 29, 2013 at 9:16
  • As Jon already commented, a column is a collection of values. Your question is how to hide the entire column based on it's value, which doesn't really make sense because a column has many values. Commented Oct 29, 2013 at 9:45
  • it actually makes sense..for example, you have a set of values and i know that there are a collection of values, but you have a value that is unacceptable that you need to hide the entire column because of that value. for example: all rows in that "value" column contain all 1's , but then a single row is actually zero. and then you decide to hide it. (i have a use for this) Commented Oct 30, 2013 at 0:51

1 Answer 1

5

Try this

array(
    'name' => 'value',
    'header' => 'Value',
    'value' => '$data->value',
    'visible' => '$data->value != 0',
    'type' => 'raw',
)
Sign up to request clarification or add additional context in comments.

2 Comments

API Reference here.
Will this hide it on the client only? or is there a chance someone could get the hands on that data without hacking the server?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.