Yii在TbGridView中的自定义列与条件的FontAwsome图标

Yii在TbGridView中的自定义列与条件的FontAwsome图标

问题描述:

我一直在尝试使用fontAwesome在列中呈现图标。我可以用图像完成它,但我无法根据True/False条件获取fontAwesome图标来显示。任何帮助,将不胜感激。Yii在TbGridView中的自定义列与条件的FontAwsome图标

这是代码,第1列是我试图用Fontawesome显示的列,不起作用,第2列使用图像并且正常工作。

<?php $this->widget('bootstrap.widgets.TbGridView',array(
'id'   => 'vpolicy-grid', 
'dataProvider' => $model->searchForPolicyIndex(), 
'filter'  => $model, 
'type'   => 'striped condensed', 
'selectableRows' => 1, // you can select only 1 row!! 
'selectionChanged' => 'function(id){ var objectId = $.fn.yiiGridView.getSelection(id); 
if (isNaN(objectId) || objectId == ""){return;} location.href = "'.$this->createUrl('policy/view'). 
'&id="+$.fn.yiiGridView.getSelection(id);}', 

'columns'=>array(
    array('name'    => 'has_open_issue', 
     'header'   => 'Issues', 
     'type'    => 'raw', 
     'value'    => '($data->has_open_issue == "N") ? "<i class="icon- fa-check icon-2x"></i>" : "<i class="icon-fa-warning-sign icon-2x"></i>"', 
     'filter'   => VFFormUtil::getFilter_YesNo(), 
     'headerHtmlOptions' => array('style' => 'text-align: center; width: 80px'), 
     'htmlOptions'  => array('style'=>'text-align: center; width: 80px'),), 
    array('name'    => 'compliance', 
     'type'    => 'raw', 
     'value'    => 'CHtml::image($data->compliance == "INSUFFICIENT" ? "images/policy_insufficient.png" : "images/policy_sufficient.png", "", array("width"=>25, "height"=>25))', 
     'filter'   => VFFormUtil::getFilter_Compliance(), 
     'headerHtmlOptions' => array('style' => 'text-align: center; width: 80px'), 
     'htmlOptions'  => array('style'=>'text-align: center; width: 80px'),), 

我也试过:

'value'=> 'CHtml::tag($data->has_open_issue == "N" ? "<i class="icon-fa-check icon-2x" style="color:green"></i>" : "<i class="icon-fa-warning-sign icon-2x" style="color:red"></i>", "", array("width"=>25, "height"=>25))', 

,并没有擦出火花。我究竟做错了什么?

你需要逃避的报价为标签的属性即

'value'=> '($data->has_open_issue == "N") ? "<i class=\"icon- fa-check icon-2x\"></i>" : "<i class=\"icon-fa-warning-sign icon-2x\"></i>"', 

,而不是

'value'=> '($data->has_open_issue == "N") ? "<i class="icon- fa-check icon-2x"></i>" : "<i class="icon-fa-warning-sign icon-2x"></i>"', 
+0

谢谢托弗,工作就像一个魅力,你的人! – user2715832