PHP code example of egor260890 / yii2-sort-extension

1. Go to this page and download the library: Download egor260890/yii2-sort-extension 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/ */

    

egor260890 / yii2-sort-extension example snippets



use egor260890\sort\Sort;

class myclass{
    use Sort;
    
    protected function getSortAttribute(): string
        {
            return 'sort_id';
        }
    
        protected function getSortGroupAttributes(): array
        {
            return [];
        }

}




<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            ...,
            ...,
            ...,
            [
                'class' => 'egor260890\sort\widgets\gridview\MoveColumn',
                'pjaxContainerSelector'=>'#new-container',
                'method'=>'products/move'
            ],

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); 

    public function actionMove($id,$action){
            try {
                $model=Products::findOne($id);
                $model->move($action);
            } catch (\DomainException $e) {
                Yii::$app->errorHandler->logException($e);
                Yii::$app->session->setFlash('error', $e->getMessage());
            }
        }