title: Yii2: Get selected rows data from gridView checkbox columns into controller
body: <p>I've view page(<code>index.php</code>) in my Yii2 project, and I'm using <em>Kartik gridView</em> for showing the data</p>
  <h3>This the view from index.php:</h3>
  <p><a href="https://i.stack.imgur.com/55E6D.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/55E6D.png" alt="enter image description here" /></a></p>
  <p>On the right side of view, I've a checkbox column.
  And I've an <strong>Export</strong> button.
  I want to export the selected name (selected by checkbox) into <code>name.txt</code> file.</p>
  <p>I've finally make the export function, but I don't know how to get the selected data from view into controller.</p>
  <p>I've try suggestions that I got from many forums, for example:</p>
  <p>I put this javascript code in my view <code>index.php</code>:</p>
  <pre><code>&lt;script&gt;
  function getRows(){
      var keys = $('#grid').yiiGridView('getSelectedRows');
      $.post({
          url: FakturOutController / exportAction,
          dataType: 'json',
          data: {keylist: keys},
          success: function(data) {
              alert('I did it! Processed checked rows.')
          },
      });
  }
  </code></pre>
  
  <p>and set the <strong>export</strong> button like this:</p>
  <pre><code>&lt;p&gt;
      &lt;button type=&quot;button&quot; onclick=&quot;getRows()&quot; class=&quot;btn btn-success&quot;&gt;Export&lt;/button&gt;
  &lt;/p&gt;
  </code></pre>
  <p>But I got nothing, the button didn't showed any action/reaction when clicked.</p>
  <h3>This is the gridView code in index.php:</h3>
  <pre><code>`&lt;?php Pjax::begin(); ?&gt;
  &lt;?=
  GridView::widget([
      'dataProvider' =&gt; $dataProvider,
      'tableOptions' =&gt; ['class' =&gt; 'table table-hover'],
      'columns' =&gt; [
          ['class' =&gt; 'yii\grid\SerialColumn',
              'header' =&gt; 'No',
          ],
          [
              'label' =&gt; 'Name',
              'value' =&gt; function($data) {
              return $data-&gt;name;
      }
          ],
          ['class' =&gt; '\kartik\grid\CheckboxColumn'],
      ],
      'toolbar' =&gt; [
          ['content' =&gt;
              Html::a('&lt;i class=&quot;glyphicon glyphicon-repeat&quot;&gt;&lt;/i&gt;', ['index'], ['data-pjax' =&gt; false, 'class' =&gt; 'btn btn-default', 'title' =&gt; 'Reset Grid'])
          ],
          '{export}',
          '{toggleData}'
      ],
      'panel' =&gt; [
          'heading' =&gt; '&lt;i class=&quot;glyphicon glyphicon-align-left&quot;&gt;&lt;/i&gt;&amp;nbsp;&amp;nbsp;&lt;b&gt;Data&lt;/b&gt;',
          'before' =&gt; '', //IMPORTANT
      ],
  ]);
  ?&gt;
  &lt;?php Pjax::end(); ?&gt;
  
  &lt;?=
      Html::a('&lt;i class=&quot; glyphicon glyphicon-export&quot;&gt;&lt;/i&gt; Export', ['export', 'userId' =&gt; $userId], ['class' =&gt; 'btn btn-success']);
  ?&gt;`
  </code></pre>
  <p>Any help would be appreciated. Thanks</p>