Yii bootstrap + TbButtonColumn widget + TbButtonGroup widget

yii bootstrap + widget TbButtonColumn + widget TbButtonGroup

Faced with such a problem:

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

But one button that I want to do with the Split drop-down list effect is 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', ), ) ), )); 
+6
source share
2 answers

I always found that when I need to display a complex element in a gridview (especially a widget), it is easier if you call a function from the controller. For example, your gridview will have columns that are defined as follows:

 '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 it will look something like this. This simply displays an example widget on the Yii-booster example page http://yii-booster.clevertech.biz/components.html#buttonDropdowns :

Edit: this is also useful because the renderButtons () callback function accepts 2 parameters: $ data and $ row. You can use $ data to access data from the gridview data provider to dynamically render the widget.

 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'=>'#'), )), ), )); } 
+5
source

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

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

Source: https://habr.com/ru/post/944178/


All Articles