A gridview with a checkbox column needs update by highlighting the column checkboxes then selecting the action via a form dropdown. After submitting the form the Post array is Blank on the controller end.
Please help, a whole weekend down the drain
<php>
views
index.php
<?php
$this -> registerJs (
'$(“document”).ready(function(){
$("#setstatus").on("pjax:start", function() {
$.pjax.reload({container:"#group"}); //
Reload GridView
});
});'
) ;
?>
<div class="group-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a('Create Group', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php Pjax :: begin ([ ‘id’ => ‘setstatus’ , ‘timeout’=> false , ‘enablePushState’ => false ,‘clientOptions’ => [‘method’ => ‘POST’ ]]) ?>
<?php //Html:: beginForm([ ‘group/bulk’ ] , ‘post’ , [‘data-pjax’ => ‘’, ‘class’=> ‘form-inline’ ]) ; ?>
<?= Html::dropDownList(‘action’,’’,[‘1’=>‘Activate’,‘0’=>‘Deactivate’],[‘class’=>‘dropdown’,])?>
<?php //Html::a(‘Update’ , [‘group/bulk’], [ ‘class’ =>‘btn btn-info’,]);?>
<?= Html:: a( Yii:: t ( ‘app’ , ‘Create {modelClass}’ , [‘modelClass’ => ‘Group’ ,]) , [‘bulk’ ], [ ‘class’ => ‘btn btn-success’ ]) ?>
<?php $form = ActiveForm:: begin ([ ‘options’ =>[‘data-pjax’ => true ], ‘id’=> ‘statusid’]) ; ?>
<?=GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'name',
[
'class' => 'yii\grid\CheckboxColumn',
'header' => 'Status',
'checkboxOptions' => function ($model, $key, $index, $column){
return [ "value" => $model->groupid,"checked" => $model->status];
}
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
<?php ActiveForm:: end () ; ?>
<?php Pjax::end(); ?>
<?php
//group controller!!! . Note the post array is empty–>
public function actionBulk(){
$action= Yii::$app->request->post('action');
$selection = (array) Yii ::$app->request->post('selection');
$ids_sql = implode(",", array_map("intval", $selection));
print_r(Yii ::$app->request->post()); //empty
print_r($ids_sql);//empty
print_r($action);//empty
//$count = Yii::$app->db->createCommand("UPDATE group SET status=$action WHERE groupid IN ($ids_sql)")->execute();
return $this->redirect(['index']);
}
<php>