octoweb/yii2-grid-view-sort

Sortable modification of standard Yii2 GridView widget

Installs: 32

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

1.0.1 2015-10-09 07:09 UTC

This package is not auto-updated.

Last update: 2025-04-02 20:38:47 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 "octoweb/yii2-grid-view-sort" "*"

or add

"octoweb/yii2-grid-view-sort" : "*"

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 octoweb\gridsort\SortableGridBehavior;

public function behaviors()
{
    return [
        'sort' => [
            'class' => SortableGridBehavior::className(),
            'sortableAttribute' => 'sortOrder'
        ],
    ];
}
  • Add action in the controller, for example:
use octoweb\gridsort\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.