title: yii2 GridView + PJAX + custom Button for ActionColumn
body: <p>OK I am trying to solve this for many hours now ... quite difficult</p>
  
  <p>So here is the problem combination:
  GridView + PJAX  + custom Button for ActionColumn</p>
  
  <p><strong>What it does correctly:</strong></p>
  
  <ul>
  <li>Requests Pjax on click</li>
  <li>Sets active flag via ajax</li>
  <li>Loads the
  new content</li>
  </ul>
  
  <p><strong>What it does NOT do:</strong></p>
  
  <ul>
  <li>keep the URL - aka AFTER the ajax call the URL in the links has changed to "person/active/123" instead of the original "person/index" .... </li>
  </ul>
  
  <p>This is highly problematic since if a user now searches or orders the columns the actionActive will be triggered again.</p>
  
  <p><strong>My ideas:</strong></p>
  
  <ul>
  <li><p>Set enablePushState = false
  Does not solve the main issue - URL in Browser window is now correct BUT url links in GridView are still "person/active/123"</p></li>
  <li><p>Override Yii::$app->request-url on AJAX call</p></li>
  </ul>
  
  <p>=> No effect</p>
  
  <pre><code>use kartik\grid\GridView;
  // VIEW 
  [
  'class'         =&gt; 'kartik\grid\ActionColumn',
  'template'      =&gt; '{active}&amp;nbsp;{view}&amp;nbsp;{update}&amp;nbsp;{delete}',      
  'buttons'       =&gt; [
     "active" =&gt; function ($url, $model) {
          if ($model-&gt;active == 1) $icon = "pause";
          else $icon = "play";
  
          return Html::a(\kartik\helpers\Html::icon($icon), $url, [
          'title'              =&gt; Yii::t('app', 'Toogle Active'),
          'data-pjax'          =&gt; '1',
          'data-toggle-active' =&gt; $model-&gt;id
      ]);
     },
  ],
  'urlCreator'    =&gt; function ($action, $model, $key, $index) {
      return \yii\helpers\Url::to(["person/" . $action, "id" =&gt; $model-&gt;id]);
  },
  'viewOptions'   =&gt; ['label' =&gt; \kartik\helpers\Html::icon("folder-open"), 'title' =&gt; Yii::t("app", 'View {modelClass}', ['modelClass' =&gt; 'Person']), 'data-toggle' =&gt; 'tooltip'],
  'updateOptions' =&gt; ['title' =&gt; Yii::t("app", 'Update {modelClass}', ['modelClass' =&gt; 'Person']), 'data-toggle' =&gt; 'tooltip'],
  'deleteOptions' =&gt; ['title' =&gt; Yii::t("app", 'Delete {modelClass}', ['modelClass' =&gt; 'Person']), 'data-toggle' =&gt; 'tooltip'],
  ],
  
  GridView::widget([
      'dataProvider'     =&gt; $dataProvider,
      'filterModel'         =&gt; $searchModel,
      'columns'            =&gt; $gridColumns,
      'pjax'               =&gt; true,
  ])
  
  // CONTROLLER
  public function actionActive($id)
  {
      $model = $this-&gt;findModel($id);
      if ($model-&gt;active == 0) $model-&gt;active = 1;
      else $model-&gt;active = 0;
  
      if (!$model-&gt;save()) {
          Yii::$app-&gt;session-&gt;addFlash("error", "Error saving");
      }
      $model-&gt;refresh();
  
      if (Yii::$app-&gt;request-&gt;isAjax) { // Render the index view
          return $this-&gt;actionIndex();
      }
      else return $this-&gt;redirect(['person/index']);
  }
  </code></pre>