kongoon
(Kongoon)
March 9, 2017, 1:22pm
21
when i set value of checkbox column and getselectedrows it’s not working…
<?=Html::button('<i class="fa fa-save"></i> ตรวจสอบคัดทิ้งเนื้อ', ['class' => 'btn btn-success', 'id' => 'choose'])?>
grid
'columns' => [
[
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' => function($model) {
return ['value' => $model->id_case];
}
],
JS
<?php $this->registerJs("
$(\"#choose\").click(function(){
var keys = $('#grid').yiiGridView('getSelectedRows');
alert(keys);
});
")?>
I used the Yii Debugger tool to isolate a deliberate exception throw under the controller using the following
Controller action:
public function actionDoit()
{
if (isset($_POST[‘keylist’]))
{
//Equivalent to: $arr=$_POST['keylist'];
$request = Yii::$app->request;
$arr = $request->post('keylist');
//Unnecessary: $keys = \yii\helpers\Json::decode($params,true);
//Extract the array $arr into individual keys separated by a comma,
$keys = implode(",",$arr);
if (is_array($arr)) {$message = "is array ";}
if ($request->isAjax) { $message .= "AJAX "; }
if ($request->isPost) { $message .= "POST "; }
throw new NotFoundHttpException('Here '.$keys.' and request is '.$message);
}
}
onigame
(Onigame)
August 8, 2017, 8:36am
23
I was also getting the "Invalid JSON data" error message.
Eventually I worked out that kartik’s code wasn’t actually sending JSON in the JQuery section – it was sending raw javascript.
Instead of:
var keys = $('#grid').yiiGridView('getSelectedRows');
$.post({
url: vUrl, // your controller action
dataType: 'json',
data: {keylist: keys},
success: function(data) {
alert('I did it! Processed checked rows.')
},
});
it should be:
var keys = $('#grid').yiiGridView('getSelectedRows');
$.post({
url: vUrl, // your controller action
dataType: 'json',
data: {keylist: JSON.stringify(keys)},
success: function(data) {
alert('I did it! Processed checked rows.')
},
});
pedroafl
(pedroafl)
July 19, 2021, 9:02pm
25
Goodnight.
I’m trying to implement an EditableColumn with checkbox, but when I try to get the data from the checkbox inside the editableColumn, I can’t. Can anybody help me ?