rezident/yii2-sortable-grid-view-widget

Sortable modification of standard Yii2 GridView widget

1.0.9 2016-03-12 23:13 UTC

This package is auto-updated.

Last update: 2024-08-28 23:43:21 UTC


README

Sortable modification of standard Yii2 GridView widget.

Installation

The preferred way to install this extension is through composer.

  • Either run
php composer.phar require --prefer-dist "rezident/yii2-sortable-grid-view-widget" "*"

or add

"rezident/yii2-sortable-grid-view-widget" : "*"

to the require section of your application's composer.json file.

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

  • Add new behavior in the AR model, for example:

use rezident\sortablegrid\SortableGridBehavior;

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

public function actions()
{
    return [
        'sort' => [
            'class' => SortableGridAction::className(),
            'modelName' => Model::className(),
        ],
    ];
}

Usage

  • Use SortableGridView as standard GridView with sortableAction option. You can also subscribe to the JS event 'sortableSuccess' generated widget after a successful sorting.
  • Use not-sortable class for row to disable sorting for this row