Tuesday 31 October 2017

yii bootstrap + widget TbButtonColumn + widget TbButtonGroup

itemprop="text">



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."




But one button
I want to do with the effect of Split dropdowns
href="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',
),

)
),

));


Answer




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:



'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 href="http://yii-booster.clevertech.biz/components.html#buttonDropdowns"
rel="nofollow">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.



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'=>'#'),
)),
),

));
}


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...