orlac / yii2-sortable
Sortable ActiveRecord for Yii 2 framework
Installs: 179
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/orlac/yii2-sortable
Requires
- php: ~5.6|~7.0
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2025-12-09 03:34:54 UTC
README
This extension for sorting ActiveRecord models.
Install
Via Composer
$ composer require orlac/yii2-sortable
Usage
Model:
use orlac\sortable\SortableBehavior; public function behaviors(){ return [ [ 'class' => SortableBehavior::className(), ], ]; } public function behaviors(){ return [ [ 'class' => SortableBehavior::className(), 'scope' => function($model){ return Model::find()->addWere('...'); } ], ]; } public function behaviors(){ return [ [ 'class' => SortableBehavior::className(), 'scope' => function($model){ return Model::find()->addWere('...'); }, 'sortColumn' => 'sort' ], ]; }
Controller
use orlac\sortable\UpAction; use orlac\sortable\DownAction; .... public function behaviors() { return [ 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['POST'], 'up' => ['POST'], 'down' => ['POST'], ], ], ]; } public function actions(){ return [ 'up' => [ 'class' => UpAction::className(), 'modelClass' => Model::className() ], 'down' => [ 'class' => DownAction::className(), 'modelClass' => Model::className() ], ]; }
View
use orlac\sortable\ActionColumn; <?php Pjax::begin(); ?> <?= GridView::widget([ ... 'columns' => [ ... [ 'class' => ActionColumn::className(), ], [ 'class' => ActionColumn::className(), 'template' => ($dataProvider->sort->getAttributeOrder('priority')) ? '{up} {down} {update} {delete}' : '{update} {delete}', 'order' => ($dataProvider->sort->getAttributeOrder('priority') === SORT_DESC) ? SORT_DESC : SORT_ASC, ], ], ]); ?> <?php Pjax::end(); ?>