Class yii\bootstrap4\ButtonToolbar
| Inheritance | yii\bootstrap4\ButtonToolbar » yii\bootstrap4\Widget » yii\base\Widget | 
|---|---|
| Uses Traits | yii\bootstrap4\BootstrapWidgetTrait | 
| Source Code | https://github.com/yiisoft/yii2-bootstrap4/blob/master/src/ButtonToolbar.php | 
ButtonToolbar Combines sets of button groups into button toolbars for more complex components.
Use utility classes as needed to space out groups, buttons, and more.
For example,
// a button toolbar with items configuration
echo ButtonToolbar::widget([
    'buttonGroups' => [
        [
            'buttons' => [
                ['label' => '1', 'options' => ['class' => ['btn-secondary']]],
                ['label' => '2', 'options' => ['class' => ['btn-secondary']]],
                ['label' => '3', 'options' => ['class' => ['btn-secondary']]],
                ['label' => '4', 'options' => ['class' => ['btn-secondary']]]
            ],
             'class' => ['mr-2']
        ],
        [
            'buttons' => [
                ['label' => '5', 'options' => ['class' => ['btn-secondary']]],
                ['label' => '6', 'options' => ['class' => ['btn-secondary']]],
                ['label' => '7', 'options' => ['class' => ['btn-secondary']]]
            ],
            'class' => ['mr-2']
        ],
        [
            'buttons' => [
                ['label' => '8', 'options' => ['class' => ['btn-secondary']]]
            ]
        ]
    ]
]);
Pressing on the button should be handled via JavaScript. See the following for details:
See also:
Public Properties
| Property | Type | Description | Defined By | 
|---|---|---|---|
| $buttonGroups | array | List of buttons groups. | yii\bootstrap4\ButtonToolbar | 
| $clientEvents | array | The event handlers for the underlying Bootstrap JS plugin. | yii\bootstrap4\BootstrapWidgetTrait | 
| $clientOptions | array | The options for the underlying Bootstrap JS plugin. | yii\bootstrap4\BootstrapWidgetTrait | 
| $options | array | The HTML attributes for the widget container tag. | yii\bootstrap4\Widget | 
Public Methods
| Method | Description | Defined By | 
|---|---|---|
| getView() | yii\bootstrap4\BootstrapWidgetTrait | |
| init() | Initializes the widget. | yii\bootstrap4\ButtonToolbar | 
| run() | yii\bootstrap4\ButtonToolbar | 
Protected Methods
| Method | Description | Defined By | 
|---|---|---|
| registerClientEvents() | Registers JS event handlers that are listed in $clientEvents. | yii\bootstrap4\BootstrapWidgetTrait | 
| registerPlugin() | Registers a specific Bootstrap plugin and the related events | yii\bootstrap4\BootstrapWidgetTrait | 
| renderButtonGroups() | Generates the button groups that compound the toolbar as specified on $buttonGroups. | yii\bootstrap4\ButtonToolbar | 
Property Details
Method Details
| public abstract \yii\web\View getView ( ) | ||
| return | \yii\web\View | The view object that can be used to render views or view files. | 
|---|---|---|
                abstract function getView();
            
        Initializes the widget.
This method will register the bootstrap asset bundle. If you override this method, make sure you call the parent implementation first.
| public void init ( ) | 
                public function init()
{
    parent::init();
    Html::addCssClass($this->options, ['widget' => 'btn-toolbar']);
    if (!isset($this->options['role'])) {
        $this->options['role'] = 'toolbar';
    }
}
            
        Defined in: yii\bootstrap4\BootstrapWidgetTrait::registerClientEvents()
Registers JS event handlers that are listed in $clientEvents.
| protected void registerClientEvents ( ) | 
                protected function registerClientEvents()
{
    if (!empty($this->clientEvents)) {
        $id = $this->options['id'];
        $js = [];
        foreach ($this->clientEvents as $event => $handler) {
            $js[] = "jQuery('#$id').on('$event', $handler);";
        }
        $this->getView()->registerJs(implode("\n", $js));
    }
}
            
        Defined in: yii\bootstrap4\BootstrapWidgetTrait::registerPlugin()
Registers a specific Bootstrap plugin and the related events
| protected void registerPlugin ( $name ) | ||
| $name | string | The name of the Bootstrap plugin | 
                protected function registerPlugin($name)
{
    $view = $this->getView();
    BootstrapPluginAsset::register($view);
    $id = $this->options['id'];
    if ($this->clientOptions !== false) {
        $options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
        $js = "jQuery('#$id').$name($options);";
        $view->registerJs($js);
    }
    $this->registerClientEvents();
}
            
        Generates the button groups that compound the toolbar as specified on $buttonGroups.
| protected string renderButtonGroups ( ) | ||
| return | string | The rendering result. | 
|---|---|---|
| throws | Exception | |
                protected function renderButtonGroups()
{
    $buttonGroups = [];
    foreach ($this->buttonGroups as $group) {
        if (is_array($group)) {
            $group['view'] = $this->getView();
            if (!isset($group['buttons'])) {
                continue;
            }
            $buttonGroups[] = ButtonGroup::widget($group);
        } else {
            $buttonGroups[] = $group;
        }
    }
    return implode("\n", $buttonGroups);
}