Yii Framework Forum: How To Set Value For Checkboxcolumn - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Set Value For Checkboxcolumn

#1 User is offline   Davey 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 125
  • Joined: 14-September 11

Posted 13 December 2013 - 06:28 AM

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?
0

#2 User is offline   amnah 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 106
  • Joined: 23-February 13

Posted 13 December 2013 - 10:57 AM

Try this:

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

0

#3 User is offline   Davey 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 125
  • Joined: 14-September 11

Posted 16 December 2013 - 03:09 AM

View Postamnah, on 13 December 2013 - 10:57 AM, said:

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.
0

#4 User is offline   amnah 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 106
  • Joined: 23-February 13

Posted 16 December 2013 - 09:03 AM

'checkboxOptions' => function($model, $key, $index, $widget) {
    return ["value" => $model->id];
},

1

#5 User is offline   Davey 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 125
  • Joined: 14-September 11

Posted 16 December 2013 - 09:08 AM

View Postamnah, on 16 December 2013 - 09:03 AM, said:

'checkboxOptions' => function($model, $key, $index, $widget) {
    return ["value" => $model->id];
},



Perfect, thanks!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users