Dear all,
I am using the CStarRating component. I try to display it and enable voting on CGridView, so far the displaying is okay but when I vote on it (e.g. click a star) the callback doesn’t triggered. I have tried using both AJAX and JQuery.getJSON as below:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'client-grid',
'dataProvider'=>$model->search(),
'afterAjaxUpdate'=>'function(id,data){ $(\'span.rating input\').rating({readOnly:false}); }',
'columns'=>array(
'client_name',
array (
'name' => 'score',
'type' => 'raw',
'value'=>'$this->grid->controller->widget("CStarRating",
array(
"name"=>"rating".$data->id_client,
"value"=>$data->score,
"starCount"=>"5",
"minRating"=>"1",
"maxRating"=>"5",
"ratingStepSize"=>"1",
"readOnly"=>false,
"htmlOptions"=>array("class"=>"rating"),
"callback"=>"function(){
url = \"/clients/update\";
jQuery.getJSON(url, {id: \'$data->id_client\', val: $(this).val()},
function(data) {
if (data.status !== \"success\"){
alert(\"error\");
}});}",),true)',
),
))); ?>
and
array (
'name' => 'score',
'type' => 'raw',
'value'=>'$this->grid->controller->widget("CStarRating",
array(
"name"=>$data->id_client,
"value"=>$data->score,
"starCount"=>"5",
"minRating"=>"1",
"maxRating"=>"5",
"ratingStepSize"=>"1",
"readOnly"=>false,
"htmlOptions"=>array("class"=>"rating"),
"callback"=>"function(){
$.ajax({
type: \"GET\",
url: \"/clients/update\",
data: \"id_client=$data->id_client&score=\" + $(this).val(),
success: function(msg){
alert(\"Sucess\")
},
error: function(xhr){
alert(\"failure\"+xhr.readyState+this.url)
}
})
}",
),true)',
),
The output HTML is fine but nothing triggered and the clients/update action is not invoked. Please advise, thank you!