ereminmdev / yii2-sortablejs
Sortable assert for Yii framework.
Installs: 1 239
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: >=7.0
- npm-asset/sortablejs: ^1.13
- yiisoft/yii2: ~2.0.1
README
Reorderable drag-and-drop lists widget for Yii framework.
Based on JavaScript library: https://github.com/RubaXa/Sortable
Install
composer require --prefer-dist ereminmdev/yii2-sortablejs
Documentation
ClientOptions: https://github.com/RubaXa/Sortable#sortable
Use
Insert widget into view:
<?= \ereminmdev\yii2\sortablejs\SortableJs::widget([
'elementSelector' => '.items',
'clientOptions' => [
'handle' => '.item-handle',
],
]) ?>
or with SortableJsAction action:
- add action to controller:
public function actions()
{
return [
'sortable' => [
'class' => 'ereminmdev\yii2\sortablejs\SortableJsAction',
],
];
}
- add widget into view:
<?= SortableJs::widget([
'elementSelector' => '.items',
'storeSetAction' => Url::toRoute(['/site/sortable', 'model' => Product::class]),
]) ?>
Tips
To refresh after ajax:
- add into view before widget
$this->registerJs('if (Sortable.active) Sortable.active.destroy();');
- or set
destroyOldBeforeThis
widget option totrue