sorting gridView rows by button click

Hi i tried to write some code which let me sort rows of gridView in Yii2 on action button click. All i need is when i click my button with action my row with this button should appear above. And row above should change place with my row which i clicked. Default my data are sorted by Id. But i think to create new column in database named ‘sortOrder’ and there I want to save my sort values. So i created this column and tried to write some function which can save my ‘sortOrder’ value and then i can sorted all my data by this column. My function now look like this:

 public function actionSortUp($id){

              $model = $this->findModel($id);


//there max value should be count(all models)

    //i need to do here something that the values are not the same but if it the same it should +2 or something to save order


                return $this->redirect('index.php?r=values%2Findex');


I got stuck there and i haven’t idea what can I do to fix that. So my idea was the crete button in gridview:

'buttons' => [

    'my_button' => function ($url, $model, $key) {

        return Html::a('up', ['sort-up', 'id'=>$model->id]);},


and when i click this buttoon my sortOrder have +1 and then this row with this id automatically after refresh page go up becosue i order by this ‘sortOrder’. Anyone have idea what can I do to fix that. I should use some array or make this function subsidiary of $model->Id? Maybe there is some resolve of problem with sorting rows in the google? But i search for this and i found only widgets which not saved my sorted value on database.