PHP code example of arogachev / yii2-sortable

1. Go to this page and download the library: Download arogachev/yii2-sortable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arogachev / yii2-sortable example snippets


$this->addColumn('table_name', 'sort', Schema::TYPE_INTEGER . ' NOT NULL');

use arogachev\sortable\behaviors\numerical\ContinuousNumericalSortableBehavior;

/**
 * @inheritdoc
 */
public function behaviors()
{
    return [
        [
            'class' => ContinuousNumericalSortableBehavior::className(),
        ],
    ];
}

function () {
    return Question::find()->where(['test_id' => $this->test_id]);
}

function ($model) {
    return $model->getNeighbors();
}

/**
 * @return \yii\db\ActiveQuery
 */
public function getNeighbors()
{
    return static::find()->where(['parent_id' => $this->parent_id]);
}

[
    'is_active' => 1,
    'is_deleted' => 0,
],

function () {
    return Yii::$app->user->can('questions.sort');
}

'controllerMap' => [
    'sort' => [
        'class' => 'arogachev\sortable\controllers\SortController',
    ],
],

use arogachev\sortable\grid\SortableColumn;

<div class="question-index" id="question-sortable">
     Pjax::begin(); 

'template' => '<div class="sortable-section">{moveWithDragAndDrop}</div>
<div class="sortable-section">{currentPosition}</div>
<div class="sortable-section">{moveForward} {moveBack}</div>',
'buttons' => [
    'moveForward' => function () {
        return Html::tag('i', '', [
            'class' => 'fa fa-arrow-circle-left',
            'title' => Yii::t('sortable', 'Move forward'),
        ]);
    },
    'moveBack' => function () {
        return Html::tag('i', '', [
            'class' => 'fa fa-arrow-circle-right',
            'title' => Yii::t('sortable', 'Move back'),
        ]);
    },
],