Skip to content

beatep/yii2-sortable-widgets

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yii2 Sortable widgets

Implementation Rubaxa/Sortable for Yii2 widgets. Position starts with 1.

Supported:

  • GridView widget.

demo

Usage

Create a new migration, change a parent to the migration class from the extension and specify the table name property:

class m140811_131705_Models_order extends \beatep\sortable\migrations\Migration
{
    protected $tableName = 'models';
}

Add the sortable behavior to your model and specify the query property:

public function behaviors()
{
    return [
        'sortable' => [
            'class' => \beatep\sortable\behaviors\Sortable::className(),
            'query' => self::find(),
        ],
    ];
}

Add the sorting action to your controller and specify the query property:

public function actions()
{
    return [
        'sorting' => [
            'class' => \beatep\sortable\actions\Sorting::className(),
            'query' => \vendor\namespace\Model::find(),
        ],
    ];
}

Add the column to your grid view and specify the sorting url like here:

echo \yii\grid\GridView::widget([
    'dataProvider' => $model->search(),
    'rowOptions' => function ($model, $key, $index, $grid) {
        return ['data-sortable-id' => $model->id];
    },
    'columns' => [
        [
            'class' => \beatep\sortable\grid\Column::className(),
        ],
        'id',
        'title',
        'order',
    ],
    'options' => [
        'data' => [
            'sortable-widget' => 1,
            'sortable-url' => \yii\helpers\Url::toRoute(['sorting']),
        ]
    ],
]);

About

🍨 Rubaxa/Sortable for Yii2

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 88.5%
  • PHP 11.2%
  • CSS 0.3%