starcode / yii2-grid-group-actions
Yii2 extension GridView with group actions
Installs: 116
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 6
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2025-01-04 20:52:27 UTC
README
Yii2 extension GridView with group actions.
Installation
Via composer
composer require "starcode/yii2-grid-group-actions:*"
or add composer.json
{ "require": { "starcode/yii2-grid-group-actions": "1.*" } }
Usage
Create group actions controller.
// ... 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], ], ]; } // ...
Output widget.
<?= 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', ], ], ]); ?>