yii2-sortable-widgets

:ice_cream: Rubaxa/Sortable for Yii2

Github stars Tracking Chart

Yii2 Sortable widgets

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(),
        ],
    ];
}

If you're using another primary key (not 'id'), you must specify it in 'pk' parameter:

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

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']),
        ]
    ],
]);

If cdn is not accessible in your country, you can use Sortable library from local dependencies:

...
    'columns' => [
        [
            'class' => \kotchuprik\sortable\grid\Column::className(),
            'useCdn' => false
        ],
        ...
    ],
...

Main metrics

Overview
Name With Ownerchuprik/yii2-sortable-widgets
Primary LanguagePHP
Program languagePHP (Language Count: 3)
Platform
License:MIT License
所有者活动
Created At2014-08-12 05:27:04
Pushed At2022-11-09 05:31:30
Last Commit At2022-07-14 03:10:38
Release Count12
Last Release Namev2.2.0 (Posted on )
First Release Name1.0 (Posted on )
用户参与
Stargazers Count61
Watchers Count10
Fork Count23
Commits Count55
Has Issues Enabled
Issues Count16
Issue Open Count0
Pull Requests Count12
Pull Requests Open Count1
Pull Requests Close Count1
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private