I have a grid view like below. Here i want to use the value of Correct answer to find which button to show.
For example if the Correct answer > 0 show tick button else show cross button
So How i will write that condition in the grid view ?
$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,
));
Thanks in advance
Try This
'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'))
Try something like this
array('header'=>'Action','value' =>array($this,'getButton')),
and in controller
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.