The preferred way to install this extension is through composer.
To install, either run
$ php composer.phar require isavon/yii2-sortablegrid "@dev"
or add
"isavon/yii2-sortablegrid": "@dev"
to the require
section of your composer.json
file.
NOTE: Refer the CHANGE LOG for details on changes to various releases.
Add SortableGridAction to your controller.
public function actions()
{
return [
SortableGridAction::SORTABLE_ACTION => [
'class' => SortableGridAction::className(),
'modelName' => Model::className(),
],
];
}
Add SortableGridBehavior to your model.
public function behaviors()
{
return [
[
'class' => SortableGridBehavior::className(),
'sortableAttribute' => 'sortOrder',
],
];
}
And add SortableGridView to your view file.
<?= SortableGridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
'id',
'name',
'created_at',
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}',
],
],
]) ?>
Done!