Yii 2.0: yii2-sortable-widgets

Implementation the jQuery UI Sortable for Yii2 widgets
1 follower

Supported:

  • GridView widget.

Usage

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

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

Add Sortable behavior to your model and specify the query:

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

Add Sorting action to your controller and specify the query:

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

Add column from the extension to widget call of GridView and specify the sorting url:

echo \yii\grid\GridView::widget([
    'dataProvider' => $model->search(),
    'columns' => [
        [
            'class' => \kotchuprik\sortable\grid\Column::className(),
            'sortingUrl' => ['sorting']
        ],
        'id',
        'title',
        'order',
    ],
]);

Resources

Be the first person to leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet