Save the new order of rows in the Sortable table database

I have researched many such problems, but I cannot find a suitable solution for me. I am using Yii2 framework in PHP nad MongoDB for my database. I am also using Yii2 sorted extension for GridView and have already installed it in my web app using composer.

Here's my GridView in my view :

<?php echo SortableGridView::widget([
    'dataProvider' => $dataProvider,
    //'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        'code_type',
        'payroll_name',
        'cpf_type',
        [    
            'label' => 'Action',    
            'content' => function ($model, $key, $index, $column) {
                 if ( ($model->company_id != null) && ($model->active == 1) ) {
                    if(in_array($model->payroll_name, array('Basic Salary', 'Overtime Pay', 'Daily/Hourly Wage', 'Commission', 'Bonus', 'Housing Allowance', 'Educational Allowance', 'Travel Allowance', 'Marriage Allowance', 'Leave Encashment', 'Reimbursement'))){
                        return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view-earnings']).'&id=' . (string)$model->_id, 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2']);
                    } else {
                        return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view-earnings']).'&id=' . (string)$model->_id, 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2'])
                        .'&nbsp'
                        . Html::button('<span class="glyphicon glyphicon-pencil"></span>', ['value' => Url::to(['update-earnings']).'&id=' . (string)$model->_id, 'class' => 'btn btn-success btn-view btn-responsive','id' => 'modalButton3'])
                        .'&nbsp'
                        . Html::a('<span class="glyphicon glyphicon-remove"></span>', ['delete-earnings', 'id' => (string)$model->_id], ['class' => 'btn btn-danger btn-responsive', 'data' => ['confirm' => 'Are you sure you want to delete this earnings item?', 'method' => 'post']])
                        .'&nbsp'
                        . Html::button('Unset as Default', ['value' => (string)$model->_id, 'class' => 'btn btn-danger btn-responsive', 'onclick'=>'unset(value)']);
                    }
                } else { 
                    return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view-earnings']).'&id=' . (string)$model->_id, 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2'])
                    .'&nbsp'
                    . Html::button('<span class="glyphicon glyphicon-pencil"></span>', ['value' => Url::to(['update-earnings']).'&id=' . (string)$model->_id, 'class' => 'btn btn-success btn-view btn-responsive','id' => 'modalButton3'])
                    .'&nbsp'
                    . Html::a('<span class="glyphicon glyphicon-remove"></span>', ['delete-earnings', 'id' => (string)$model->_id], ['class' => 'btn btn-danger btn-responsive', 'data' => ['confirm' => 'Are you sure you want to delete this earnings item?', 'method' => 'post']])
                    .'&nbsp'
                    . Html::button('Set as Default', ['value' => (string)$model->_id, 'class' => 'btn btn-info btn-responsive', 'onclick'=>'set(value)']);
                }
            }
        ]
    ],   
    'sortableAction' => Yii::$app->request->baseUrl . '/index.php?r=payroll-items/earnings-index'
]); ?>

      

Model:

public function behaviors()
{
    return [
        'sort' => [
            'class' => SortableGridBehavior::className(),
            'sortableAttribute' => 'sortOrder'
        ],
    ];
}

      

Controller:

public function actions()
{
    return [
        'sort' => [
            'class' => SortableGridAction::className(),
            'modelName' => PayrollItems::className(),
        ],
    ];
}

      

I found this problem but I don't know what to put inside updateworkshops.php

(see main answer) since I am using MongoDB and not MySQL.

As with my current progress, I can only drag and drop the rows of the GridView, but the new order still cannot be saved in my database.

Can someone please explain to me how to do this?

+3
jquery php mongodb jquery-ui-sortable yii2


source to share


No one has answered this question yet

See similar questions:

1
How to store jQuery UI ordered table positions in MySQL database?

or similar:

2302
Add table row in jQuery
468
jQuery: number of rows in a table
153
jquery UI Sort with table and width
133
JQuery UI Sorting Position
98
jQuery UI Sort then write order to database
7
jQuery Sortable - keep order when inserting new element into list
3
How to control visibility of buttons in ActionColumn yii2 GridView when using yii2 RBAC with rules class?
0
How can I check the current order of rows in a sorted table?
0
yii2 rendering after sending request
-1
Yii2 Codeception Functional Tests - Click OK on Confirmation Dialog



All Articles
Loading...
X
Show
Funny
Dev
Pics