handysolver/yii2-sortable-list-view-widget

Sortable modification of standard Yii2 ListView widget

dev-master 2017-09-05 13:53 UTC

This package is not auto-updated.

Last update: 2024-04-25 05:17:28 UTC


README

Sortable modification of standard Yii2 ListView widget.

Credits

This library has been picked up from himiklab's gridview sortable and has been customised to work with ListView. Great work himiklab!

Installation

The preferred way to install this extension is through composer.

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

or add

"handysolver/yii2-sortable-list-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 handysolver\sortablelist\SortableListBehavior;

public function behaviors()
{
    return [
        'sort' => [
            'class' => SortableListBehavior::className(),
            'sortableAttribute' => 'sortOrder'
        ],
    ];
}
  • Add action in the controller, for example:
use handysolver\sortablelist\SortableListAction;

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

Usage

  • Use SortableListView as standard ListView with sortableAction option. You can also subscribe to the JS event 'sortableSuccess' generated widget after a successful sorting.