2

How to get parameters using gridview checkbox on selected rows. I have button for multiple action in header of gridview.

Html::button('<i class="glyphicon glyphicon-download-alt"></i>', ['type'=>'button', 'title'=>Yii::t('app', 'Bulk Reject'), 'class'=>'btn btn-success', 'onclick'=>'var keys = $("#pjax-list-'.$model->id.'").yiiGridView("getSelectedRows"); alert(keys ? "Reject " + keys + " selected applicant(s)" : "No rows selected for download");']),

I get result number of selected rows. If i select 4 rows. I get below result in alert box.

1,2,3,4

I get only keys of selected rows like this 1,2,3,4... in alert box. How to get active models data using in gridview. like pk id.

I have method in controller

public function actionDoreject($userid, $jobid) {
.....
}

I want to get userid and jobid parameters like this doreject/userid=$model->userid&jobid=$model->jobid

I figured out how to get these parameters using javascript.

Further more I added property checkboxOptions like below:

'columns' => [
        ['class' => '\kartik\grid\CheckboxColumn', 
        'checkboxOptions' => function ($model, $key, $index, $column) {
                return ['data-uid' => $model->user_id, 'data-jid'=>$model->job_id];
            }],
        [

view source code of checkbox after using checkboxOptions

<input type="checkbox" name="selection[]" value="1" data-uid="6" data-jid="1">

How to get selected rows data attributes? I get error if I try to get attributes using this code $("#pjax-list-'.$model->id.'").yiiGridView("getSelectedRows").attr("data-uid")

Or is there any simple way to solve this issue?

Nand Lal
  • 682
  • 1
  • 11
  • 25

0 Answers0