yii bootstrap + 小部件 TbButtonColumn + 小部件 TbButtonGroup
面对这样的问题:
表格由来自 Bootstrap (来自 yii-booster)的小部件 TbGridView 形成。在 TbButtonColumn 列中,我形成了“编辑/删除等”。
但是我想用一个按钮来处理拆分下拉列表的效果
http://yii-booster.clevertech.biz/components.html#buttonDropdowns
$this->widget('bootstrap.widgets.TbGridView', array(
'id'=>'customer-grid',
'type'=>'striped bordered condensed',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'surname',
'name',
'middlename',
'dateOfBirth',
array(
'class'=>'bootstrap.widgets.TbButtonColumn',
'template'=>'{add} {list} {update} {print_act}',
'buttons'=>array
(
'add' => array
(
'label'=>'Назначить прием',
'icon'=>'plus',
'url'=>'Yii::app()->createUrl("reception/create", array("id"=>$data->id))',
'options'=>array(
'class'=>'btn btn-small',
),
),
'list' => array
(
'label'=>'Список предоставленных услуг',
'icon'=>'list white',
'url'=>'Yii::app()->createUrl("patient/update", array("id"=>$data->id))',
'options'=>array(
'class'=>'btn btn-small btn-info',
),
),
'update' => array
(
'label'=>'Изменить данные Пациента',
'icon'=>'pencil white',
'url'=>'Yii::app()->createUrl("customer/update", array("id"=>$data->id))',
'options'=>array(
'class'=>'btn btn-small btn-success',
),
),
'print_act' => array
(
'label'=>'Печать акта выполненных работ',
'icon'=>'print',
'url'=>'Yii::app()->createUrl("customer/printAct", array("id"=>$data->id))',
'options'=>array(
'class'=>'btn btn-small',
),
),
),
'htmlOptions'=>array(
'style'=>'width: 220px',
),
)
),
));
最佳答案
我一直发现,当我需要在 GridView (尤其是小部件)中呈现复杂元素时,如果从 Controller 调用函数会更容易。例如,您的 gridview 将具有这样定义的列:
'columns'=>array(
'surname',
'name',
'middlename',
'dateOfBirth'
...
array(
'name'=>'fieldName',
//call the function 'renderButtons' from the current controller
'value'=>array($this,'renderButtons'),
),
)
然后在你的行动中看起来像这样。这只是呈现来自 Yii-booster 示例页面 http://yii-booster.clevertech.biz/components.html#buttonDropdowns 的示例小部件:
编辑:这也很有帮助,因为回调函数 renderButtons() 接受 2 个参数:$data 和 $row。您可以使用 $data 访问来自 gridview 的数据提供程序的数据,以便动态呈现小部件。
public function renderButtons($data, $row) {
$this->widget('bootstrap.widgets.TbButtonGroup', array(
'size'=>'large',
'type'=>'inverse', // '', 'primary', 'info', 'success', 'warning', 'danger' or 'inverse'
'buttons'=>array(
array('label'=>'Inverse', 'items'=>array(
array('label'=>'Action', 'url'=>'#'),
array('label'=>'Another action', 'url'=>'#'),
array('label'=>'Something else', 'url'=>'#'),
'---',
array('label'=>'Separate link', 'url'=>'#'),
)),
),
));
}
关于twitter-bootstrap - yii bootstrap + 小部件 TbButtonColumn + 小部件 TbButtonGroup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16352998/