title: Yii2 Get Value of Each GridView Row on Button Click (Get Multiple Values on One Button Click)
body: <p>I have a <code>GridView</code> and in my <code>ActionColumn</code>, there is a "View Payslip" button on each row. "Create Payslip" will be seen instead of "View Payslip" if the user has not created any payslip yet. I also have a button outside this <code>GridView</code> named "Approve Payslips". This button is disabled by default and will only be enabled if <strong>all</strong> buttons indicate "View Payslip".
  <img src="https://i.stack.imgur.com/d00FX.png" alt="enter image description here"></p>
  
  <p><strong>PHP</strong><br>
  This is code for the "Approve Payslips" button:</p>
  
  <pre><code>&lt;?php echo Html::button('Approve Payslips', ['value' =&gt; 'approve-w', 'class' =&gt; 'btn btn-warning btn-responsive approve-w', 'style' =&gt; 'display:none', 'onclick'=&gt;'approveWeekly(value)']); ?&gt;
  </code></pre>
  
  <p><strong>JavaScript</strong><br>
  I tried this but it doesn't work since it passes an ID and I have multiple values to pass:</p>
  
  <pre><code>function approveWeekly(id){
      $.ajax({
          url: 'index.php?r=periods/approveweekly',
          dataType: 'json',
          method: 'GET',
          data: {id : id},
          success: function (data, textStatus, jqXHR) {
             $.pjax.reload({container:'#w_gridview'});
          },
          error: function (jqXHR, textStatus, errorThrown) { 
              alert("error");
          }
      });
  }
  </code></pre>
  
  <p>Also tried this one but it's not working again because I just got this code from my "Email Selected Payslips" button (check the photo above):</p>
  
  <pre><code>function approveBiMonthly(){       
      var keylist = $('#b_gridview').yiiGridView('getSelectedRows');
      //alert(keylist);
      keylist = '\''+keylist+'\'';
      $.ajax({
          url: 'index.php?r=periods/approvebimonthly', // your controller action
          dataType: 'json',
          method: 'GET',
          data: {keylist: keylist},
          success: function (data, textStatus, jqXHR) {
          //alert(keylist);
          },
          error: function (jqXHR, textStatus, errorThrown) { 
              alert('error');
          }
      });
  }
  </code></pre>
  
  <p>Anyone has any idea or knows how to implement this kind of feature? I don't know what to put in my <code>jQuery</code> code anymore. I'm just a newbie. Hope someone could be of help.</p>