我目前无法使用bootstrap在GridView中显示某些列。
我的代码中有这个:
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'viewrank-grid',
'type'=>'striped bordered condensed',
'cssFile' => Yii::app()->request->baseUrl . "/css/cgridview.css",
'dataProvider' => $rank_model->search(),
'columns' => array(
array(
'name' => 'id',
'header' => 'rank_id',
),
array(
'name' => 'rank_title',
'header' => 'Rank',
),
array(
'header' => 'Access',
'value' => 'Privilege::model()->findByAttributes(array(\'module_id\'=>' . $module_model->id . ',\'rank_id\'=>$data->id)) ? \'Allowed\': \'Not Allowed\'',
),
array(
'class' => 'CButtonColumn',
'template' => '{view} {allow} {deny}',
'htmlOptions' => array('width' => '10%;', 'style' => 'text-align: center'),
'buttons' => array(
'view' => array(
'label'=>'View',
'imageUrl' => Yii::app()->request->baseUrl . "/images/gridview_icons/view.png",
'url' => 'Yii::app()->createUrl("management/viewrank",array("id"=>$data->id))',
),
'allow' => array(
'label'=>'Allow',
'imageUrl' => Yii::app()->request->baseUrl . "/images/gridview_icons/approve.png",
'url' => 'Yii::app()->createUrl("management/allowmodule",array("rank_id"=>$data->id,"module_id"=>' . $module_model->id . '))',
'visible' => '!(Privilege::model()->findByAttributes(array(\'module_id\'=>' . $module_model->id . ',\'rank_id\'=>$data->id)))',
),
'deny' => array(
'label'=>'Deny',
'imageUrl' => Yii::app()->request->baseUrl . "/images/gridview_icons/delete.png",
'url' => 'Yii::app()->createUrl("management/denymodule",array("rank_id"=>$data->id,"module_id"=>' . $module_model->id . '))',
'visible' => 'Privilege::model()->findByAttributes(array(\'module_id\'=>' . $module_model->id . ',\'rank_id\'=>$data->id))',
)
)
)
),
));
有没有办法我可以添加一个条件,如果rank_id = 2则隐藏图标。?
提前致谢。
答案 0 :(得分:0)
更改CButtonColumn允许按钮中的可见条件
'visible' => '(($data->id) &&
!(Privilege::model()->findByAttributes(array(\'module_id\'=>' .
$module_model->id . ',\'rank_id\'=>$data->id))))',
),
答案 1 :(得分:0)
我看到rank_id是数据提供程序中存在的字段,因此它将在$ data对象中可用:
'visible' => '($data->rank_id!=2)',