title: Yii2 pjax.reload not working for gridview records update
body: <p>I have developed rows per page functionality for grid-view. With a Drop-down having options like 5,10,25,50,100. On-change any of the drop-down option I need to show selected number of rows for grid-view.  For That I have created a Pjax container having my grid-view like :</p>
  
  <pre><code>&lt;?php
  
  use yii\helpers\Html;
  use yii\grid\GridView;
  use yii\widgets\Pjax;
  
  $this-&gt;title = 'Test Cards';
  $this-&gt;params['breadcrumbs'][] = $this-&gt;title;
  ?&gt;
  
  &lt;div class="row"&gt;
      &lt;div class="test-card-index"&gt;
          &lt;?= $this-&gt;render('_search', [ 'model' =&gt; $searchModel ]) ?&gt;   
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;?php Pjax::begin(['id' =&gt; 'test_grid_pjax', 'enablePushState' =&gt; false, 'timeout' =&gt; 1000000]); ?&gt; 
  
  &lt;div class="row"&gt;
  &lt;?= GridView::widget([
      'dataProvider' =&gt; $dataProvider,
      'class' =&gt; 'table table-bordered responsive',
      'id' =&gt; 'test_grid',
      'summary' =&gt; "&lt;div class='summary'&gt;&lt;label&gt;Showing {begin} - {end} of {totalCount} items.&lt;/label&gt;&lt;/div&gt; &lt;div class='col-sm-6 pageDropdown'&gt; &lt;label&gt;Records per page&lt;/label&gt;  ".Html::dropDownList('pageSize', (int) Yii::$app-&gt;session-&gt;get('pageSize', Yii::$app-&gt;params['defaultPageSize']), Yii::$app-&gt;params['rowPerPage'], ['id' =&gt; 'pageSize', 'class' =&gt; 'form-control', 'onchange' =&gt; 'return reloadGrid("test_grid_pjax",this.value)']) . "&lt;/div&gt;",
      'layout' =&gt; '{summary}{items}&lt;div class="pager"&gt;{pager}&lt;/div&gt;',
      'options' =&gt; ['class' =&gt; 'main-grid grid-view full-table'],
      'columns' =&gt; [
          'cc_amount',
          'cc_number',                    
          'cc_type',
          'cc_status'
          ],
      ]);
  ?&gt;
  &lt;/div&gt;
  
  &lt;?php Pjax::end(); ?&gt;
  </code></pre>
  
  <p>_search.php looks like :</p>
  
  <pre><code>&lt;?php
  use yii\helpers\Html;
  use yii\widgets\ActiveForm;
  ?&gt;
  
  &lt;div class="test-card-search"&gt;
  
      &lt;?php $form = ActiveForm::begin([
      'action' =&gt; ['index'],
      'method' =&gt; 'get',
      'options' =&gt; ['data-pjax' =&gt; true , 'class'=&gt;'search_form form-horizontal' ]
  
  ]); ?&gt;
  
  &lt;div class="form-group"&gt;
      &lt;div class="row"&gt;
          &lt;div class="col-md-6"&gt;
              &lt;?= Html::activeLabel($model, 'cc_number',['class'=&gt;'control-label col-sm-5']); ?&gt;
              &lt;div class="col-sm-6"&gt;
                  &lt;?= Html::activeTextInput($model, 'cc_number', ['class'=&gt;'form-control col-sm-5','autofocus'=&gt;true]); ?&gt;                                
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class="form-group"&gt; 
      &lt;div class="row"&gt;
          &lt;div class="col-md-6"&gt;
              &lt;?= Html::activeLabel($model, 'cc_type',['class'=&gt;'control-label col-sm-5']); ?&gt;
              &lt;div class="col-sm-6"&gt;                                
                  &lt;?= Html::activeDropDownList($model, 'cc_type',[ "RESTRICTED" =&gt; Yii::t('app','RESTRICTED'), "UNRESTRICTED" =&gt; Yii::t('app','UNRESTRICTED')],['prompt' =&gt; Yii::t('app','All Types'), 'class'=&gt;'form-control col-sm-5']); ?&gt;                                
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class="form-group"&gt;
      &lt;div class="col-md-5"&gt;&lt;/div&gt;
  
      &lt;div class="col-md-3"&gt;
          &lt;div class="form-group"&gt;
              &lt;?= Html::submitButton('Search', ['class' =&gt; 'btn btn-blue']) ?&gt;
              &amp;nbsp;&amp;nbsp;&amp;nbsp;
              &lt;?= Html::resetButton('Reset', ['class' =&gt; 'btn btn-primary','id'=&gt;'resetButton','onclick'=&gt;"location.href = '".Yii::$app-&gt;urlManager-&gt;createUrl('testcard/index')."';"]) ?&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;  
  
  &lt;?php ActiveForm::end(); ?&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>action in Controller looks like:</p>
  
  <pre><code>public function actionIndex()
  {
  
      if (Yii::$app-&gt;request-&gt;get('pageSize')) {
          Yii::$app-&gt;session-&gt;set('pageSize', (int) Yii::$app-&gt;request-&gt;get('pageSize'));
      }
  
      // to set the selected page number of the grid
      if (Yii::$app-&gt;request-&gt;get('page')) {
          Yii::$app-&gt;session-&gt;set('page',(int)Yii::$app-&gt;request-&gt;get('page'));
      } else {
          Yii::$app-&gt;session-&gt;set('page',1);
      }
  
      $searchModel = new TestCardSearch();
      $dataProvider = $searchModel-&gt;search(Yii::$app-&gt;request-&gt;queryParams);
  
      return $this-&gt;render('index', [
          'searchModel' =&gt; $searchModel,
          'dataProvider' =&gt; $dataProvider,
      ]);
  }
  </code></pre>
  
  <p>function reloadGrid() is like:</p>
  
  <pre><code>&lt;script type='text/javascript'&gt;
  function reloadGrid(id, value, url) {
  $.pjax.reload({
      container: "#" + id,
      data: $('#search_form').serialize() + "&amp;pageSize=" + value,
      url: url,
      push: false,
      replace: false,
      timeout: 1000000
  });
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>On Searching thru any of the fields its reloads entire page and also sets search parameters in url. 
  Another problem is that on changing 'pageSize' dropdown it works fine for first time only, on every other attempts it shows error in console like:</p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'reload' of undefined
  at reloadGrid (index:53)
  at HTMLSelectElement.onchange (index:1)
  </code></pre>
  
  <p>Is it a problem of JS conflicts?
  I have tried many solutions by googling it, but not get it worked.</p>