vendredi 10 novembre 2017

How to display $dataprovider column value on a button click in Yii2

I want to display the value(s) from a column that is in my $dataprovider. Below is what I have done

Action

$dataProvider = new SqlDataProvider([
       'sql' => $sql,
       'totalCount' => $count,
        'pagination' => [
               'pageSize' => 30,
           ],
   ]);


    return $this->render('viewcreated', [
        'dataProvider' => $dataProvider,
        'model' => $this->findModel($id),
        'id'=> $model->id
        /*'searchModel' => $searchModel*/
    ]);

My view

<?= GridView::widget([
         'dataProvider' => $dataProvider,
          /*'filterModel' => $searchModel,*/
          'id'=>'grid',
       'columns' => [

        ['class' => 'yii\grid\CheckboxColumn'],

        'Meter Serial Number',
        'Issued To',
        'Store',           

 ],
<button type="button" class="btn btn-success" id="myid">View Selected Rows</button>

In my javascript i have done

$(document).ready(function () {      

 $('#myid').click(function() {

    var strValue = "";

    $('input[name="selection[]"]:checked').each(function() {

    if(strValue!="")
        {
        strValue = strValue + " , " + this.value;

        }
    else 
        strValue = this.value;


});
     alert(strValue);
 })  

});

Now when i click on the button I only see the ID and not the value in it.

Here is the view when I click on the button

I have searched for it but unable to find a solution

Any help would be highly appreciated.




Aucun commentaire:

Enregistrer un commentaire