Yii2 GridView widget base on jQuery UI sortable widget., (*1)
Installation
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require --prefer-dist "oonne/yii2-sortable-grid-view" "*"
or add, (*4)
"oonne/yii2-sortable-grid-view" : "*"
to the require section of your composer.json
file., (*5)
Usage
-
Add to your database new unsigned int
attribute, such sequence
., (*6)
-
Add new behavior in the active record model, for example:, (*7)
use oonne\sortablegrid\SortableGridBehavior;
public function behaviors()
{
return [
'sort' => [
'class' => SortableGridBehavior::className(),
'sortableAttribute' => 'sequence'
],
];
}
- Add action in the controller, for example:
use oonne\sortablegrid\SortableGridAction;
public function actions()
{
return [
'sort' => [
'class' => SortableGridAction::className(),
'modelName' => Model::className(),
],
];
}
- Add SortableGridView in the view, for example:
use oonne\sortablegrid\SortableGridView;
SortableGridView::widget([
'dataProvider' => $dataProvider,
'sortableAction' => ['/bannersuper/sort'],
'columns' => [
[
'class' => 'yii\grid\SerialColumn',
'contentOptions' => ['class' => 'sortable-handle'],
],
[
'attribute' => 'sName',
],
]
])