oonne/yii2-sortable-grid-view

Yii2 GridView widget base on jQuery UI sortable widget

Installs: 2 470

Dependents: 1

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-extension

1.0.0 2017-07-19 12:24 UTC

This package is auto-updated.

Last update: 2024-04-18 17:04:59 UTC


README

Yii2 GridView widget base on jQuery UI sortable widget.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist "oonne/yii2-sortable-grid-view" "*"

or add

"oonne/yii2-sortable-grid-view" : "*"

to the require section of your composer.json file.

Usage

  • Add to your database new unsigned int attribute, such sequence.

  • Add new behavior in the active record model, for example:

use oonne\sortablegrid\SortableGridBehavior;

public function behaviors()
{
    return [
        'sort' => [
            'class' => SortableGridBehavior::className(),
            'sortableAttribute' => 'sequence'
        ],
    ];
}
  • Add action in the controller, for example:
use oonne\sortablegrid\SortableGridAction;

public function actions()
{
    return [
        'sort' => [
            'class' => SortableGridAction::className(),
            'modelName' => Model::className(),
        ],
    ];
}
  • Add SortableGridView in the view, for example:
use oonne\sortablegrid\SortableGridView;

SortableGridView::widget([
    'dataProvider' => $dataProvider,
    'sortableAction' => ['/bannersuper/sort'],
    'columns' => [
        [
            'class' => 'yii\grid\SerialColumn',
            'contentOptions' => ['class' => 'sortable-handle'],
        ],
        [
            'attribute' => 'sName',
        ],
    ]
])