Gridview page position after action

In gridview there are some buttons (view, update, delete and some custom action) in one ActionColumn. When using one of these, delete for example, relative action in controller redirect, in my case, to index and the page, obiovsly, return at his top.

Is there a way to leave the page in the position where the record was deleted, for example at the middle or at the bottom page?

The same if using one of search field in column, after an action they disappear, is there a way to leave it without reinitialize?

Should be possible with Ajax / Pjax.

Then you can submit actions/search & reload the GridView without reloading the whole page.

Sorry I have no concrede code-example but you can just Google for "Yii2 Ajax Gridview" or "Yii2 Pjax Gridview".

Regards

Thank you, I will take a look…

Use of pjax is quite easy, but don’t solve my problem. I think because after an action - deletion of one record for example - the controller must return something. This, in my case:


    	$this->findModel($id)->delete();

    	return $this->redirect(['index']);

and the page obviously is inizialized again. I don’t know if it is possible to do something…

Instead of the redirect try sending a response.

When I’m not wrong the order should be something like this:

  1. GridView => Send ajax/pjax request to controller.

  2. Controller => Handle request and send ajax/pjax RESPONSE back. (instead of the redirect)

  3. GridView => Catch the "success" response coming from controller.

  4. GridVIew => Refresh the grid with pjax / ajax.

Then you should not have a page reload.

Regards