Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8736585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:20:12+00:00 2026-06-13T10:20:12+00:00

Q : how to checked some checkbox at cgridview? Status : I’ve done a

  • 0

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,
        ),

    ),
)); ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:20:14+00:00Added an answer on June 13, 2026 at 10:20 am

    The problem lies in the $current_reviewers variable, it is not accessible within the php expression that is passed as the checked value. For this you can use an anonymous function and to use the outside variable, use the use keyword:

    'checked'=>function($data, $row) use ($current_reviewers){
                    return in_array($data->id, $current_reviewers);
    }
    

    Check the usage of use keyword.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to check checkbox like $('#riderCheck').attr('checked','true') on some condition. but the problem is
I have a for loop that check whether some checkboxes are checked foreach (CheckBox
I have a checkbox which in some cases may be disabled and checked using
I've checked some similar threads, but either they were unclear or too advanced for
I have application in which check-box tree is present. I want to pre-populate the
I have a CheckBox that, when checked/unchecked will toggle the Enabled property of some
I know there are lots of questions related to Custom ListView with CheckBox but
I need some help again. I have a GridView with CheckBox es in first
I have a input checkbox that is checked and disabled when some JS runs
I would like to use Javascript to check if a checkbox has been checked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.