Yii Framework Forum: Cgridview Column Htmloptions - If/then Expression - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cgridview Column Htmloptions - If/then Expression Is it possible to have an if/then expr in htmlOptions that uses $ Rate Topic: -----

#1 User is offline   Lynette 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 16-November 12

Posted 04 September 2013 - 03:21 PM

I am using a gridview, and have 3 columns that are textfields. I only want these textfields visible if a flag
is set to 1...here is the syntax I've tried, but it always evaluates to true....
<?php
        $this->widget('zii.widgets.grid.CGridView', array(
            'id' => 'work-order-item-grid',
            'dataProvider' => $dataProviderWOI,
                  . . .
            'columns' => array(
                  . . .
              array(
                    'name' => 'reserve',
                    'value' => 'CHtml::textField("reserve[$data->id]",$data->reserve,array("style"=>"width:50px;", ))',
                    'type' => 'raw',
                    'htmlOptions' => '$data->service->reservable==\'0\'' ? array("width" => "50px", 'style' => 'opacity:0') : array("width" => "50px", 'style' => 'text-align: right;'),
                ),

0

#2 User is offline   Lynette 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 16-November 12

Posted 04 September 2013 - 04:01 PM

...fixed it...

htmlOptions has no access to $data, but cssClassExpression does...

Here's the code that works:

array(                     'name' => 'reserve',                     'value' => 'CHtml::textField("reserve[$data->id]",$data->reserve,array("style"=>"width:50px;", ))',                     'cssClassExpression' => '$data->service->reservable==0 ? \'noreserve\' : \'\';',                     'type' => 'raw',                     'htmlOptions' => array("width" => "50px", 'style' => 'text-align: right;'),                 ),


and in my .css file
.grid-view table.items td.noreserve { 	opacity: 0; }


Now, the textfield is only visible when the flag is set to 1.
0

#3 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 890
  • Joined: 19-February 13
  • Location:India

Posted 04 September 2013 - 11:47 PM

Hi you can try this
for e.g

  'value' => '($data["active"] == 1 ? " ":CHtml::tag("div",  array("style"=>"float: left; margin:5px; cursor:pointer" ,"onclick"=>"updatecustomer({$data["user_id"]})","id" => "{$data["user_id"]}","href"=>"javascript:void(0);") ,
                                                    CHtml::tag("img", array( "src" => "'.Yii::app()->request->baseUrl . '/images/update.png"))
                                    ).CHtml::tag("div",  array("style"=>"float: left; margin:5px; cursor:pointer" ,"onclick"=>"deletecustomer({$data["user_id"]})","id" => "{$data["user_id"]}","href"=>"javascript:void(0);") ,
                                                    CHtml::tag("img", array( "src" => "'.Yii::app()->request->baseUrl . '/images/delete.png"))
                                    ))',




And it's simple example..
'value' => '($data["active"] == 1 ? " ":"abc")',

Thanks,
Ankit Modi
Skype : amodi06
0

#4 User is offline   Lynette 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 16-November 12

Posted 05 September 2013 - 12:04 PM

Thanks for the reply!! I have only been developing in Yii for about 8 months and only recently joined this forum...
0

#5 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 890
  • Joined: 19-February 13
  • Location:India

Posted 05 September 2013 - 10:33 PM

Have you resolved this problem or not? if you resolved this please post your code so it's may be some help to other.
Thanks,
Ankit Modi
Skype : amodi06
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users