I have three items listed in yii cgridview,each row has a checkbox there,on clicking the status of the current row item should be updated in the database.Please provide some ideas for achieving this.
You can user ajax property of cgridview columns array. Please find the example below.
array(
'header'=>'Status',
'type'=>'raw',
'value'=>'CHtml::CheckBox("$data->active",$data->active,array(
"ajax" => array(
"type"=>"POST",
"url"=> ApplicationConfig::getURL("user", "twitterFeed", "changeStatus",array("feed_id"=>$data->feed_id)),
"dataType"=>"text",
"data" => array("ap_programType_id" => $data->feed_id),
"success" => "js:function(html){
if(html==\"1\"){
$(\"#active$data->feed_id\").attr(\"checked\",\"checked\");
window.location.reload()
}
else if(html==\"0\"){
$(\"#active$data->feed_id\").attr(\"checked\",false);
window.location.reload()
}
}",
"error"=>"function (xhr, ajaxOptions, thrownError){
alert(xhr.statusText);
alert(thrownError);}",
),
"style"=>"width:50px;","feed_id"=>$data->feed_id,"id"=>"active".$data->feed_id))',
'htmlOptions'=>array("width"=>"50px"),
),