Gridview Get Selected Colum

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: &#036;arr=&#036;_POST['keylist'];


       &#036;request = Yii::&#036;app-&gt;request;


       &#036;arr = &#036;request-&gt;post('keylist');


       


       //Unnecessary: &#036;keys = &#092;yii&#092;helpers&#092;Json::decode(&#036;params,true);


       


       //Extract the array &#036;arr into individual keys separated by a comma,


       &#036;keys = implode(&quot;,&quot;,&#036;arr);


                  


       if (is_array(&#036;arr)) {&#036;message = &quot;is array &quot;;}


       if (&#036;request-&gt;isAjax) { &#036;message .= &quot;AJAX &quot;; }


       if (&#036;request-&gt;isPost) { &#036;message .= &quot;POST &quot;; }


       throw new NotFoundHttpException('Here '.&#036;keys.' and request is '.&#036;message);


    } 

}

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.')

   },

});



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 ?