Php 在可排序表的数据库中保存新的行顺序
我已经研究了很多这样的问题,但似乎找不到适合我的解决方案。我在PHP和MongoDB中为我的数据库使用Yi2框架。我还使用了,并且已经使用composer在我的web应用程序中安装了它 这是我的视图中的GridView:Php 在可排序表的数据库中保存新的行顺序,php,jquery,mongodb,yii2,jquery-ui-sortable,Php,Jquery,Mongodb,Yii2,Jquery Ui Sortable,我已经研究了很多这样的问题,但似乎找不到适合我的解决方案。我在PHP和MongoDB中为我的数据库使用Yi2框架。我还使用了,并且已经使用composer在我的web应用程序中安装了它 这是我的视图中的GridView: <?php echo SortableGridView::widget([ 'dataProvider' => $dataProvider, //'filterModel' => $searchModel, 'columns' =>
<?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'])
.' '
. 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'])
.' '
. 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']])
.' '
. 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'])
.' '
. 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'])
.' '
. 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']])
.' '
. 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'
]); ?>
控制器:
public function behaviors()
{
return [
'sort' => [
'class' => SortableGridBehavior::className(),
'sortableAttribute' => 'sortOrder'
],
];
}
public function actions()
{
return [
'sort' => [
'class' => SortableGridAction::className(),
'modelName' => PayrollItems::className(),
],
];
}
我发现了这个,但我不知道在updateworkshops.php
(见顶部答案)中放什么,因为我使用的是MongoDB而不是MySQL
与我当前的进度一样,我只能拖动GridView行,但新的顺序仍然无法保存在数据库中
有人能给我解释一下怎么做吗?使用事务性数据库似乎很难编码,您可以随时扩展
SortableGridBehavior
,实现您自己的gridSort
和beforeInsert
方法来正确使用MongoDB。