I’m still migrating from yii to yii2 and now I am working on the sorting of an GridView with ajax.
I decided to use kotchuprik/yii2-sortable-widgets because of the UI, but the documentation lacks a bit, if everything works on sorting with JS, but the new order isn’t saved to the database. There is no error in the JS console, the post request looks good, so far. Did anyone use this extension and know what is wrong?
View:
echo GridView::widget([
'dataProvider' => $dataProvidel,
'columns' => [
...
],
'options' => [
'data' => [
'sortable-widget' => 1,
'sortable-url' => \yii\helpers\Url::toRoute(['/../sorting']),
]
],
]);
Controller:
public function actions()
{
return [
'sorting' => [
'class' => \kotchuprik\sortable\actions\Sorting::className(),
'query' => BrancheCheckliste::find(),
'orderAttribute' => 'position',
],
];
}
model BrancheCheckliste:
public function behaviors() {
return [
'sortable' => [
'class' => \kotchuprik\sortable\behaviors\Sortable::className(),
'query' => self::find(),
'orderAttribute' => 'position',
],
];
}
What does work is saving the right value in my position field on creating new entries, this code comes from the behavior.
Thanks!