You are viewing revision #1 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.
With the adoption of PJax on Yii2 things have change quite a bit with GridView when it comes to work with them in AJAX mode. It will probably be confusing at the beginning, but then you will soon realize how powerful the new approach is.
Using PJax widgetThe way to work with GridView in AJAX mode, is by using the PJax widget. The basic usage is like the following:
// ... configuration here ]); \yii\widgets\Pjax::end();\yii\widgets\Pjax::begin(); = GridView::widget([
Thats it, from now, the links and forms (filtering) on your GridView widget will work on ajax mode. But wait a minute, how come the action buttons do not work on AJAX mode? Well, if you check closely the rendered HTML, you will see that the links do have the HTML5 attribute
data-pjax="0". That means that if you don't wish PJax to handle your links, you need to add this HTML5 attribute to them.
How to Update my GridViewYou will surely missing
$('#grid').yiiGridView('update')and wondering how to do it with
PJax. The following code comes to the rescue:
For more information about the options that you can pass to the
reload function, please check the PJax plugin code.
PJaxwidget works with any links and/or forms that are inside its
close()statements. That means, that this tutorial is also valid for
LinkPager, etc... Anything that holds a link and/or a form.