Skip to content

twixoff/yii2-sortable-grid-view-widget

 
 

Repository files navigation

Sortable GridView Widget for Yii2

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 "himiklab/yii2-sortable-grid-view-widget" "*"

or add

"himiklab/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 himiklab\sortablegrid\SortableGridBehavior;

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

Scopes

Sometimes a table contains sort orders for multiple scopes. For example, a list of filters linked to a specific category. The scopeAttribute can be used to segment the sequence list. New items automatically get the next sort order in the segment.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 78.2%
  • JavaScript 21.8%