yii2: GridView filters and Pjax are not working correctly

I’m using Gridview widget with Pjax. Sorting works fine. But when I enter keyword in filter, it tries to submit another form on the page using POST and page refreshes (or the form shows validation errors) instead of sending GET (like sorting does). In other words Pjax/Gridview doesn’t know which form it should submit. I added ID to the grid but it didn’t help. The grid is loading dynamically in Modal window. Configuration is below:


\yii\widgets\Pjax::begin();

echo \yii\grid\GridView::widget([
    'id'=>'job-gridview',
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'layout' => "{items}\n{pager}",
    'columns' => [
        'name',
        'status',
    ],
]);

\yii\widgets\Pjax::end();

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 23 (4 by maintainers)

Most upvoted comments

I have a solution for this

put this code for begin ajax

Pjax::begin([‘id’ => ‘admin-crud-id’, ‘timeout’ => false, ‘enablePushState’ => false,]);

mybe can help.

For those who encountered this problem. Remember too…

  • put <form> between Pjax::begin and GridView::widget (This prevent pjax submit wrong form).
  • set unique id for GridView widget, not just Pjax otherwise u may get id collision because of auto generated id.

Did you try to set an id on Pjax ? e.g. :

\yii\widgets\Pjax::begin(['id'=>'pjax-job-gridview']);