How To Set Value For Checkboxcolumn

As far as i see, the yii\grid\CheckboxColumn gives all checkboxes a value of 1. How can i change this, so the value is the primary key of the model used in the Gridview?




<?php

echo GridView::widget([

   'dataProvider' => $dataProvider,

   'columns' => [

      [

        'class' => 'yii\grid\CheckboxColumn',

        'checkboxOptions' => []

      ],

[..]

?>

I probably need to change something in the checkboxOptions?

Try this:




'checkboxOptions' => ["value" => $yourValue]



Yes, but i want to use the primary key of the model used in the dataprovider. In Yii 1.x you could use $data->id for this for example.




'checkboxOptions' => function($model, $key, $index, $widget) {

    return ["value" => $model->id];

},



Perfect, thanks!