yii bootstrap + widget TbButtonColumn + widget TbButtonGroup

Bot*_*tov 6 yii twitter-bootstrap

yii bootstrap + widget TbButtonColumn + widget TbButtonGroup

面对这样的问题:

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

但是我想用一个按钮来解决Split下拉菜单的效果 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',
            ),
        ) 
    ),
));
Run Code Online (Sandbox Code Playgroud)

Kev*_*vin 5

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

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

然后在你的行动中看起来像这样.这只是从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'=>'#'),
        )),
      ),
   ));
}
Run Code Online (Sandbox Code Playgroud)