PHP code example of starcode / yii2-grid-group-actions

1. Go to this page and download the library: Download starcode/yii2-grid-group-actions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

starcode / yii2-grid-group-actions example snippets

 

    // ...
    public $modelClass = 'app\models\User';
    
    // ...
    public function actions()
    {
        return [
            'delete-group' => [
                 'class' => GroupAction::className(),
                 'run' => function($model) {
                      $model->delete();                 
                 }
            ],
            'publish-group' => [
                'class' => GroupAction::className(),
                'changeAttributes' => ['status' => User::STATUS_ACTIVE],
            ],
        ];
    }
    // ...

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'actionsButtonsOptions' => [
        'buttonsTemplate' => '{delete-group}',
        'buttons' => [
            'delete-group' => function($url, $widget) {
                $options = array_merge([
                    'form' => $widget->formId,
                    'formaction' => $url,
                    'formmethod' => $widget->formMethod,
                    'name' => 'submit',
                    'class' => 'btn btn-danger',
                ], $widget->buttonOptions);
                return Html::submitButton('<span class="glyphicon glyphicon-trash"></span>', $options);
            },
        ]
    ],
    'filterModel' => $searchModel,
    'columns' => [
        'id',
        'fullName',
        'email:email',
        [
            'class' => 'yii\grid\ActionColumn',
        ],
    ],
]);