twitter-bootstrap yii 引导程序 + 小部件 TbButtonColumn + 小部件 TbButtonGroup

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16352998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 17:04:09  来源:igfitidea点击:

yii bootstrap + widget TbButtonColumn + widget TbButtonGroup

twitter-bootstrapyii

提问by Botir Ziyatov

yii bootstrap + widget TbButtonColumn + widget TbButtonGroup

yii 引导程序 + 小部件 TbButtonColumn + 小部件 TbButtonGroup

Faced with such a problem:

面对这样的问题:

Table is formed by the widget TbGridView from bootstrap (from yii-booster). In the column TbButtonColumn I form the "edit / delete, etc."

表格由 bootstrap 的小部件 TbGridView 形成(来自 yii-booster)。在 TbButtonColumn 列中,我形成了“编辑/删除等”。

But one button I want to do with the effect of Split dropdowns http://yii-booster.clevertech.biz/components.html#buttonDropdowns

但是我想用拆分下拉列表的效果做一个按钮 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',
            ),
        ) 
    ),
));

采纳答案by Kevin

I've always found that when I need to render a complex element in a gridview (especially a widget) it's easier if you call a function from the controller. For example your gridview would have columns that are defined like this:

我一直发现,当我需要在 gridview(尤其是小部件)中渲染复杂元素时,如果从控制器调用函数会更容易。例如,您的 gridview 将具有如下定义的列:

'columns'=>array(
    'surname',
    'name',
    'middlename',
    'dateOfBirth'
    ...
    array(
        'name'=>'fieldName',
        //call the function 'renderButtons' from the current controller
        'value'=>array($this,'renderButtons'),
    ),
 )

And then in your action would look something like this. This just renders the example widget from Yii-booster example page http://yii-booster.clevertech.biz/components.html#buttonDropdowns:

然后在你的行动中看起来像这样。这只是呈现来自 Yii-booster 示例页面http://yii-booster.clevertech.biz/components.html#buttonDropdowns的示例小部件:

Edit: This is also helpful because of the callback function renderButtons() accepts 2 parameters: $data and $row. You can use $data to access data from the gridview's data provider in order to dynamically render a widget.

编辑:这也很有帮助,因为回调函数 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'=>'#'),
        )),
      ),
   ));
}

回答by jmarkmurphy

I would do this by adding another column. Both TbColumnButton abd TbButtonGroup are both widgets. You can add a button group by

我会通过添加另一列来做到这一点。TbColumnButton 和 TbButtonGroup 都是小部件。您可以通过以下方式添加按钮组

...
array(
    'class'=>'bootstrap.widgets.TbButtonColumn',
),
array(
    'class'=>'bootstrap.widgets.TbButtonGroup',
    ...
),