Yii Framework Forum: CCheckBoxColumn not checked after ajax call - Yii Framework Forum

Jump to content

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

CCheckBoxColumn not checked after ajax call In a CGridView Rate Topic: -----

#1 User is offline   lilianjee 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 18-March 12

Posted 13 April 2012 - 07:00 AM

Hi all,

I have a small issue with a CCheckBoxColumn in a CGridView.

I created a CGridview and use a CCheckBoxColumn to select a row. I need to store in a cookie the list of row selected ( I also use pagination), so I implemented a ajax call like this :

In the controller I have
public function actionaddQuestion()
	{
echo "Test OK";
}


in the view I have :
$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'tblquizz-grid',
    'dataProvider'=>$modelQuestion->listquestion(),
    'columns'=>array(
    	   array(
                'class'=>'CCheckBoxColumn',
 		'id'=>"cid_".$modelQuestion->INUMQUEST,
 		'selectableRows' => 2,
 						
 		'checkBoxHtmlOptions' => array( "ajax" => 
                                                array("type"=>"POST", 
						       "url"=>CController::createUrl("tblquizz/addQuestion"),
							"update"=>"#section_info", 
			        			),
 		
 						)
 						
 		 
                ),


So when I click on the checkbox, the ajax method is call and I can read the post value.
But Afterthat the checkbox is not checked. If I click again, I call again the ajax method but checkbox still not checked.

So please tell me in that case how I can have the checkbox checked. Should we implement in a different way ?
0

#2 User is offline   wisp 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 192
  • Joined: 04-February 11

Posted 13 April 2012 - 11:53 AM

I'm not sure, but could it be that the view where the checkbox is in, get refreshed after the ajax request, therefore resetting it's original state?
0

#3 User is offline   codesutra 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 613
  • Joined: 15-March 11
  • Location:India

Posted 17 July 2012 - 12:38 PM

i have the same issue here. But still not get any stable solution for it.

A small issue with checkbox.But taking lot of time to get it resolved.Any body can suggest me a good solution for it. I have also post my problem on This link

Any help from an expert would be appreciated.

Thanks in Advance.

Jayant
CodeSutra
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,416
  • Joined: 16-February 11
  • Location:Japan

Posted 17 July 2012 - 08:40 PM

You can use 'name', 'value' or 'checked' property of CCheckBoxColumn to set the initial status of checkboxes.

http://www.yiiframew...CCheckBoxColumn
0

#5 User is offline   codesutra 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 613
  • Joined: 15-March 11
  • Location:India

Posted 19 July 2012 - 02:19 PM

View Postsoftark, on 17 July 2012 - 08:40 PM, said:

You can use 'name', 'value' or 'checked' property of CCheckBoxColumn to set the initial status of checkboxes.

http://www.yiiframew...CCheckBoxColumn


Doesn't work yet. :(
CodeSutra
0

#6 User is offline   compact_corpse 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 24-May 11

Posted 19 July 2012 - 04:32 PM

You'll have to read the value of the cookie in the 'checked' property to check the box:

'columns'=>array(
           array(
                'class'=>'CCheckBoxColumn',
                'id'=>"cid_".$modelQuestion->INUMQUEST,
                'selectableRows' => 2,
                                                
                'checkBoxHtmlOptions' => array( "ajax" => 
                                                array("type"=>"POST", 
                                                       "url"=>CController::createUrl("tblquizz/addQuestion"),
                                                        "update"=>"#section_info", 
                                                        ),
                                                ),
                'checked'=>(isset(Yii::app()->request->cookies['cookie_name'])) ? 
                                                Yii::app()->request->cookies['cookie_name']->value : 0;
                                                
                 
                ),


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