title: How to select data from gridview to form in yii2
body: <p>I have to insert data into 'production' table. The productid, productname, batchno is stored in  a table 'productbatch'. I want to select these fields from gridview to the form on clicking on the gridview. How can I do that?
  index.php of producbatch - </p>
  
  <pre><code>&lt;?php
  
  use yii\helpers\Html;
  use yii\grid\GridView;
  
  /* @var $this yii\web\View */
  /* @var $searchModel frontend\modules\production\models\ProductbatchSearch */
  /* @var $dataProvider yii\data\ActiveDataProvider */
  
  $this-&gt;title = 'Productbatches';
  $this-&gt;params['breadcrumbs'][] = $this-&gt;title;
  ?&gt;
  &lt;div class="productbatch-index"&gt;
  
      &lt;h1&gt;&lt;?= Html::encode($this-&gt;title) ?&gt;&lt;/h1&gt;
      &lt;?php // echo $this-&gt;render('_search', ['model' =&gt; $searchModel]); ?&gt;
  
      &lt;p&gt;
          &lt;?= Html::a('Create Productbatch', ['create'], ['class' =&gt; 'btn btn-success']) ?&gt;
      &lt;/p&gt;
  
      &lt;?= GridView::widget([
          'dataProvider' =&gt; $dataProvider,
          'filterModel' =&gt; $searchModel,
          'columns' =&gt; [
              //['class' =&gt; 'yii\grid\SerialColumn'],
              ['class' =&gt; 'yii\grid\CheckboxColumn'],
              'itemid',
              'productname',
              'batchno:ntext',
              //'mfgdate',
              //'expdate',
              // 'mrp',
              // 'rate',
  
              ['class' =&gt; 'yii\grid\ActionColumn'],
          ],
      ]); ?&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>_form of production</p>
  
  <pre><code>&lt;?php
  
  use yii\helpers\Html;
  use yii\widgets\ActiveForm;
  use yii\web\View;
  /* @var $this yii\web\View */
  /* @var $model frontend\modules\production\models\Production */
  /* @var $form yii\widgets\ActiveForm */
  ?&gt;
  
  &lt;div class="production-form"&gt;
  
      &lt;?php $form = ActiveForm::begin(); ?&gt;
  
      &lt;?= $form-&gt;field($model, 'productiondate')-&gt;textInput() ?&gt;
  
      &lt;?= $form-&gt;field($model, 'itemid')-&gt;textInput() ?&gt;
  
      &lt;?= $form-&gt;field($model, 'productname')-&gt;textInput(['maxlength' =&gt; true]) ?&gt;
  
      &lt;?= $form-&gt;field($model, 'batchno')-&gt;textInput(['maxlength' =&gt; true]) ?&gt;
  
      &lt;?= $form-&gt;field($model, 'prodqty')-&gt;textInput() ?&gt;
  
      &lt;div class="form-group"&gt;
          &lt;?= Html::submitButton($model-&gt;isNewRecord ? 'Create' : 'Update', ['class' =&gt; $model-&gt;isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?&gt;
      &lt;/div&gt;
  
      &lt;?php ActiveForm::end(); ?&gt;
  
  &lt;/div&gt;
  &lt;?php
      $this-&gt;RegisterJs ( "
      $('document').ready(function(){
          // $('#".Html::getInputId($model, 'mrp')."').keyup(function(){ 
          //              var total = this.value;
          //              var percent = 10;
          //              var discount_value = this.value - ((total / 100) * percent);
          //             $('#".Html::getInputId($model, 'rate')."').val(discount_value);    
          //          });
           var keys = $('#grid').yiiGridView('getSelectedRows');
      });
  
      ", View::POS_END);
    ?&gt;
  </code></pre>