Sortable modification of standard Yii2 ListView widget.
This library has been picked up from himiklab's gridview sortable and has been customised to work with ListView. Great work himiklab!
The preferred way to install this extension is through composer.
- Either run
php composer.phar require --prefer-dist "handysolver/yii2-sortable-list-view-widget" "*"
or add
"handysolver/yii2-sortable-list-view-widget" : "*"
to the require
section of your application's composer.json
file.
-
Add to your database new
unsigned int
attribute, suchsortOrder
. -
Add new behavior in the AR model, for example:
use handysolver\sortablelist\SortableListBehavior;
public function behaviors()
{
return [
'sort' => [
'class' => SortableListBehavior::className(),
'sortableAttribute' => 'sortOrder'
],
];
}
- Add action in the controller, for example:
use handysolver\sortablelist\SortableListAction;
public function actions()
{
return [
'sort' => [
'class' => SortableListAction::className(),
'modelName' => Model::className(),
],
];
}
- Use SortableListView as standard ListView with
sortableAction
option. You can also subscribe to the JS event 'sortableSuccess' generated widget after a successful sorting.