amorangi
(Yiiframework)
1
How do I pass a variable to htmlOptions in CGrisView? I wish to color-code a number:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'aaaa-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
.
.
array(
'name'=>'amount',
'value'=>'number_format($data->amount,2)',
'htmlOptions'=>array('style'=>'text-align:right; color:$data->amount_color'),
),
doesn’t work, and neither does
'htmlOptions'=>array('style'=>'text-align:right; color:'.$data->amount_color),
What am I doing wrong?
amorangi
(Yiiframework)
2
Figured it out - should have been doing this:
'htmlOptions'=>array('style'=>'text-align:right; color:'.$model->amount_color),
The problem is it encodes the whole column, when I want to do code each cell individually. I suppose I have to put html into the value field?
Flavio
(Flavioleonelferreira)
3
this way works:
array(
'name'=>'amount',
'value'=>'number_format($data->amount,2)',
'cssClassExpression'=>'$data->amount_color',
),
<style>
.red {color: red;}
.green {color: green;}
.blue {color: blue;}
</style>
probably there is a better way
deimos21
(Mwalker)
4
Is there any way to pass $data to array in htmlOptions?? I need id of data in selected row to create ajax link.
...
'class'=>'CLinkColumn',
'label'=>'zobacz',
'header'=>'Zobacz',
'url'=>CController::createUrl('sis/UpdateStr')),
'linkHtmlOptions'=>array(
'ajax'=>array(
'type'=>'GET',
'update'=>'.info',
'url'=>CController::createUrl('sis/UpdateStr'),
'data'=>array('strId'=>'$data->id'),
),
),
...

xicath
(Xicath)
5
#amorang : I use this
'cssClassExpression'=>'$data->amount_color==\'red\' ? \'selected_row\' : \'\' ' //css class name
#amorangi
better use harcode link in value :
'type'=>'raw',
'value'=>'"<a href=\"#\" onclick=\"\">Update</a>"'
although it’s a bit rude… 
amorangi
(Yiiframework)
6
Thanks, that works great!
abud
(Ariefbudiyono)
7
hello deimos, do you has solved this problems?? becouse i have same problems with u.
thanks