jeudi 23 novembre 2017

yii2 gridview checkbox pjax pagination

I have a view in which I have a detailview and a gridview. The Grid view is with checkbox with pagination. I am using Pjax to stop reloading the page. By default my all check boxes are checked, But when i move to next page all the checked checkbox or selected checkbox are unchecked.

<?php Pjax::begin(['id'=>'pj',
            'timeout' => false,
            'enablePushState' => true,
            'clientOptions' => ['method' => 'POST']]); //id is used for jquery opertaion  ?>
        <?= GridView::widget([
         'dataProvider' => $dataProvider,
          /*'filterModel' => $searchModel,*/
          'id'=>'gv',

          'columns' => [

         ['class' => 'yii\grid\CheckboxColumn', 'checkboxOptions' => function($d) {
             return ['value' => $d['meter_id']];
         }],

         'Meter_Serial_Number',

         'Issued_To',
         'Store',
         'Meter_Version'
       ],
]); ?>
        <?php Pjax::end(); ?>

JS

<?php
$url = Url::toRoute(['/ogpheader/setpdf','id'=>$model->id]);
$script = <<< JS
$(document).ready(function () {  

  $("#chk input:checkbox").prop("checked", true);


$('#myid').on('click',function(e) {

e.preventDefault();    
 var strValue = $(this);        
    $('input[name="selection[]"]:checked').each(function() {

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

        }
    else 
       strValue = this.value;     

});
    //alert(strValue);
$.ajax({
     url: '$url',
     type: 'POST',
     dataType: 'json',
     data: {data:strValue},         
     success: function(data) {
        alert(data);
     },
  });
  }) 
  });
  JS;
  $this->registerJs($script, static::POS_END);
  ?>

How to retain the checkbox values? Any help would be highly appreciated.




Aucun commentaire:

Enregistrer un commentaire