我有一个如下所示的网格视图。在这里,我想使用正确答案的值来找到要显示的按钮。
例如,如果正确答案> 0显示勾选按钮 否则显示十字按钮
那么我将如何在网格视图中编写该条件?
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'product-table',
'dataProvider'=>Question::model()->searchCustom(1),
'columns'=>array(
array('name'=>'qnid'),
array('name'=>'question'),
array('header'=>'Correct Answer','value' =>array($this,'getCorrectAnswer')),
array(
'header'=>'Acton',
'class'=>'CButtonColumn',
'template'=>'{tick}| {cross}' ,
'buttons' => array ('tick' => array('imageUrl'=>Yii::app()->request->baseUrl.'/images/correct.png'),
'cross' => array('imageUrl'=>Yii::app()->request->baseUrl.'/images/correct.png'))
),
),
'itemsCssClass' => 'table table-striped table-bordered bootstrap-datatable datatable',
'cssFile'=>false,
));
提前致谢
答案 0 :(得分:1)
试试这个
'buttons' => array ('tick' =>
array('imageUrl'=>Yii::app()->request->baseUrl.'/images/correct.png',
'visible'=>'Correct Answer > 0'),
'cross' => array('imageUrl'=>Yii::app()->request->baseUrl.'/images/correct.png',
'visible'=>'Correct Answer <= 0'))
答案 1 :(得分:-1)
尝试这样的事情
array('header'=>'Action','value' =>array($this,'getButton')),
并在控制器中
function getButton($data) {
$correct_answer = // find it
if($correct_answer > 0) {
$button = '<a href="#" class="tick"></a>';
}
else {
$button = '<a href="#" class="cross"></a>';
}
return $button;
}