How Refresh Grid


(Qnev89) #1

Hi,

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


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

but it’s not work!


(Kburton) #2

Try this:




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




(Qnev89) #3

I try this, but it not work too


(Kburton) #4

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?


(Qnev89) #5

Yes in Yii 2 is different! Any other ideas?


(Nicola) #6

Use Pjax




Pjax::begin();

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

Pjax::end();



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

Yii2 Pjax documentation


(Kvisweswaran) #7

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.


(Qnev89) #8

example with linkSelector and formSelector ??


(Kvisweswaran) #9

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).