Q : how to checked some checkbox at cgridview?
Status : I’ve done a gridview with checkbox. but I don’t know how to pre-check some check box. $current_reviewers is an array. I would like to match with $current_reviewers and checkbox to pre-check at gridview.
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'acc-recei-grid',
'dataProvider'=>$model->search_reviewerlist(),
'filter'=>$model,
'columns'=>array(
array(
'class' => 'CCheckBoxColumn',
'selectableRows' => 2,
'checkBoxHtmlOptions' => array(
'name' => 'userids[]',
),
'value'=>'$data->id',
'checked'=>'(in_array($data->id, $current_reviewers) ? 1 : ""',
),
'username',
array(
'type'=>'raw',
'value'=>'$data->id',
//'filter'=>array('style'=>'visible:none'),
//'headerHtmlOptions'=>array('style'=>'width:0px; display:none; border:none; textdecoration:none'),
'htmlOptions'=>array('style'=>'display:none; border:none;', 'class'=>'user-id'),
//'header'=>false,
//'filter'=>false,
),
),
)); ?>
The problem lies in the
$current_reviewersvariable, it is not accessible within the php expression that is passed as thecheckedvalue. For this you can use an anonymous function and to use the outside variable, use theusekeyword:Check the usage of
usekeyword.