How Refresh Grid


how you refresh gridview with js? I try with this cod


but it’s not work!

Try this:


I try this, but it not work too

Ah, I assumed that it was the same as in Yii 1.1.x. I’m not sure of the recommended way to refresh the grid in Yii 2.


Maybe the applyFilter method will do it?

Yes in Yii 2 is different! Any other ideas?

Use Pjax


echo GridView::widget([...]);


Then write your JS code to handle the refresh of the grid.

Yii2 Pjax documentation

As mentioned by Nicola, by enclosing the gridview within Pjax widget, you can automatically refresh the grid. Any link (on click) or form (on submit), enclosed within the Pjax widget will trigger the grid refresh automatically, if you have set its data-pjax property.

Alternatively, you can set the linkSelector and formSelector properties within the Pjax widget.

example with linkSelector and formSelector ??

For example, if you want to target pjax refresh only on the following two things


<a class=‘my-link’>XYZ</a>

<form id=‘my-form’></form>


then you can set

'linkSelector' => ''

'formSelector' => '#my-form'

Disclaimer: Not tested or used this (just my understanding of the way it should be).