pheme/yii2-toggle-column

Provides a toggle data column and action

Installs: 671 961

Dependents: 13

Suggesters: 0

Security: 0

Stars: 23

Watchers: 7

Forks: 21

Open Issues: 5

Type:yii2-extension

0.8 2020-07-09 16:07 UTC

This package is not auto-updated.

Last update: 2024-12-21 19:18:42 UTC


README

Provides a toggle data column and action

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist pheme/yii2-toggle-column "*"

or add

"pheme/yii2-toggle-column": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by :

// In your Controller
use pheme\grid\actions\ToggleAction;

public function actions()
{
	return [
		'toggle' => [
			'class' => ToggleAction::className(),
			'modelClass' => 'path\to\your\Model',
			// Uncomment to enable flash messages
			//'setFlash' => true,
		]
	];
}

// In your view
use yii\grid\GridView;
use yii\widgets\Pjax;

Pjax::begin();

GridView::widget(
	[
		'dataProvider' => $dataProvider,
		'filterModel' => $searchModel,
		'columns' => [
			'id',
			[
				'class' => '\pheme\grid\ToggleColumn',
				'attribute' => 'active',
				// Uncomment if  you don't want AJAX
				// 'enableAjax' => false,
			],
			['class' => 'yii\grid\ActionColumn'],
		],
	]
);

Pjax::end();