lynkizer
(Kizere)
1
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;'),
),
lynkizer
(Kizere)
2
…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.
Ankit_Modi
(Ankit Modi)
3
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")',
lynkizer
(Kizere)
4
Thanks for the reply!! I have only been developing in Yii for about 8 months and only recently joined this forum…
Ankit_Modi
(Ankit Modi)
5
Have you resolved this problem or not? if you resolved this please post your code so it’s may be some help to other.