I am trying to modify the CRUD and trying to persist the values of checked checkboxes after the Search or new page so that when user clicks on the save button, i can save it to database.
My GridView is something like
<?php Pjax::begin(); ?>
<?=
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
[
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' => function($model, $key, $index, $widget) {
return ["value" => $model->id, ];
},
],
'rollno',
'username',
'name',
'phoneNumber',
],
]);
?>
<?php Pjax::end(); ?>
and the JS is:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#submit-form').on('click',function() {
var keys = $('#w1').yiiGridView('getSelectedRows');
alert(keys[0]);
$.post({
type :'POST',
cache : false,
url: 'index.php?r=/users/testdemo',
dataType: 'json',
data: {keylist: keys},
success: function(data) {
alert(data);
}
});
});
});
</script>
Please Help!!!