How Refresh Grid

Hi,

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


$('#books-heads').yiiGridView('init');

but it’s not work!

Try this:




$.fn.yiiGridView.update('books-heads');



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.

EDIT:

Maybe the applyFilter method will do it?

Yes in Yii 2 is different! Any other ideas?

Use Pjax




Pjax::begin();

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

Pjax::end();



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

[html]

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

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

[/html]

then you can set




'linkSelector' => 'a.my-link'

'formSelector' => '#my-form'



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