knik/yii2-sortable-widgets

Implementation Rubaxa/Sortable for Yii2. Sortable grid view inside.

Installs: 70

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 23

Type:yii2-extension

v2.0.2 2016-06-10 15:58 UTC

This package is auto-updated.

Last update: 2024-04-07 20:43:55 UTC


README

Join the chat at https://gitter.im/kotchuprik/yii2-sortable-widgets

Implementation Rubaxa/Sortable for Yii2 widgets.

Supported:

  • GridView widget.

demo

Latest Stable Version Total Downloads Monthly Downloads Latest Unstable Version License

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 \kotchuprik\sortable\migrations\Migration
{
    protected $tableName = 'models';
}

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

public function behaviors()
{
    return [
        'sortable' => [
            'class' => \kotchuprik\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' => \kotchuprik\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' => \kotchuprik\sortable\grid\Column::className(),
        ],
        'id',
        'title',
        'order',
    ],
    'options' => [
        'data' => [
            'sortable-widget' => 1,
            'sortable-url' => \yii\helpers\Url::toRoute(['sorting']),
        ]
    ],
]);