porcelanosa / yii2-toggle-column
Yii2 Extenstion for GridView toggle column
Installs: 43
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: >=7.1
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2025-01-06 01:29:06 UTC
README
Installation
composer require porcelanosa/yii2-toggle-column
Usage
In controller file add action
use porcelanosa\yii2togglecolumn\ToggleAction; use app\models\Artists; class ArtistsController extends Controller { //............. public function actions() { return [ 'toggle' => [ 'class' => ToggleAction::className(), 'modelClass' => Artists::className(), // Uncomment to enable flash messages //'setFlash' => true, 'attribute' => 'active', 'primaryKey' => 'id' ], ] } //....... }
I view file add column to the GridView
<?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ *['class' => 'yii\grid\SerialColumn'], 'id', [ 'class' => 'app\modules\admin\components\columns\ToggleColumn', 'attribute' => 'active', // Uncomment if you don't want AJAX 'enableAjax' => true, 'contentOptions' => ['style' => 'width:50px;'] ], ['class' => ActionColumn::className()], ], ]); ?>