我正在研究CGridView
在 Wii 框架的小部件上显示/隐藏特定列数据。
我有一个CButtonColumn
包含 3 个按钮的。但是,在某些情况下,我想为特定行显示不同的内容。我有 3 个不同的条件来确定特定行的显示内容。
以下说明了我想要做的事情:
| 1 | Title A | [hide][view][update] <-- if (condition == 'a')
| 2 | Title B | [hide][view][update] <-- if (condition == 'a')
| 3 | Title C | display text or link or button <-- if (condition == 'b')
| 4 | Title D | display alternative buttons <-- if (condition == 'c')
我在这里采取的最佳方法是什么?
我不能'visible'=> $model->processingStatus != "processed"
在列上使用,因为这会删除整个列。我需要定位每一行。
我应该'visible'
在每个单独的按钮上使用参数吗?我已经使用下面注释掉的代码尝试了这个,但它破坏了页面。仅供参考:我已经成功尝试了 CButtonColumn 本身的“可见”参数,但这不是我需要的。另外不确定它正在读取哪一行的状态。
或者我应该向控制器添加一个功能?让它执行 if/else 语句并返回要显示的内容。这将如何工作?
这是我的代码:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'my-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'name'=>'myid',
'header'=>'ID',
),
'Title',
array(
'class'=>'CButtonColumn',
'visible'=> $model->status != "done",
'template'=>'{hide}{view}{update}',
'buttons'=>array(
'hide'=>array(
'label'=>'Hide', //Text label of the button.
'imageUrl'=>Yii::app()->request->baseUrl . '/img/icons/bulb-off.png' //Image URL of the button.
//'click'=>'function(){alert("Toggle Hide!");}', //A JS function to be invoked when the button is clicked.
//'options'=>array(), //HTML options for the button tag.
//'url'=>'javascript:void(0)', //A PHP expression for generating the URL of the button.
//'visible'=> $model->status == "done", //A PHP expression for determining whether the button is visible.
),
'view'=>array(
//Text label of the button.
'label'=>'View',
//Image URL of the button.
'imageUrl'=>Yii::app()->request->baseUrl . '/img/icons/view-record.png'
),
'update'=>array(
'label'=>'Update/Edit',
'imageUrl'=>Yii::app()->request->baseUrl . '/img/icons/edit-pencil.png',
'url'=>'Yii::app()->createUrl("metadataandchapters/create?bookid=" . $data->bookid)',
)
)
)
)
)); ?>
希望我在这里有足够的意义!