Add function to page number in yii2 gridview

I have a problem which have to be easy, but I cant find solution. I have a grid view like this:


echo  GridView::widget([

    'dataProvider' => $dataProviderCountry,

    'filterModel' => $searchModelCountry,

    'columns' => [

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

        'name'=>'check1'],

        [ 'attribute' => 'description',

        'label' =>'Country',],

    ['class' => 'yii\grid\ActionColumn', 'template' => '{view}'],

    ],

]);

I am developing a check all function, so I have a js function for each checkbox, but I need to add one more thing, one you go from one page to other you lose you have check checkboxs in table but dont have them in page, so I need to add onclick action to page number to check the temp table and if the value is in the table to set it like check, but I cant find how to give this propriety to the page numbers because it is done with grid view. Or if you know some other methods to do it it can be good also. This is my js code.


$(function (){

var keys = [];

$(document).on('click','.checkboxCntr',function (){

value= parseInt($(this).val());

console.log($(this).prop('checked'));

  if($(this).prop('checked'))

  {      keys.push(value);  

  }

  else

  {var index = keys.indexOf(value);

 if (index > -1) {

 keys.splice(index, 1);  }    }    console.log(keys);

})    ;});

Hi, Alexei,

When using CheckboxColumn in your Gridview, you can do this:

[color="#859900"][font="Menlo, Monaco, Consolas,"][/font][/color]




var keys = $('#grid').yiiGridView('getSelectedRows');

// keys is an array consisting of the keys associated with the selected rows



[see this doc]

i solve this part but now i have other one more funny. When I am changing the page, I lose the selected checkbox ( I have them in temporary table but I dont have them like checked so it create a bug that you can select the same checkbox more times). I have a app with a lot of rows so I need to move from page to page and still to see what was and what is not checked. TX