CstarRating displays radio buttons when change pages.

Here is my problem:

My stars display properly when I don’t change to another page:

Here is my codes in my _view.php and my controller about pages

Any ideas about why?

_view.php:


div <class="rating">


$rating = Rating::model()->findByPk($data->rating_id); 


if ( isset($rating->vote_average) ){

         $value = round($rating->vote_average,0);

         }else{

         $value = 0;

         }


$this->widget('CStarRating',array(

         'name'=>'rating'.$data->rating_id, // an unique name

        'starCount'=>5,

        'readOnly'=>true,

        'value'=>$value, 

));

?>

I have added the afterAjaxUpdate but it seems like it is not correct…because it will render stars but only 2stars…instead of 5.


<?php $this->widget('zii.widgets.CListView', array(

            'dataProvider'=>$notesDataProvider,

            'itemView'=>'/notes/_view',

            'sortableAttributes'=>array(

                             // 'name',

                              'create_time',  

                               ),  

           'afterAjaxUpdate'=>'function(id,data){ $(\'div.rating \').rating(); }', 

        ));

?>

See images:

I changed one line to

‘afterAjaxUpdate’=>‘function(id,data){ $(\‘div.rating input \’).rating(); }’,

Problem solved…

I have the same problem. I use CStarRate in CGridView:


array(

                 'name'=>'Ocjena',

                 

                 'type'=>'raw',

                 'value'=>'$this->grid->controller->widget("CStarRating",

                                array(

                                        "id"=>"rating_".$data->idKnjiga,

                                        "starCount"=>"5",

                                       

                                        "maxRating"=>"5",

                                        "ratingStepSize" => 0.5,

                                        "minRating"=>0.5,

                                        "readOnly"=>true, 

                                        "name"=>$data->idKnjiga,

                                       

                                        "value"=>round($data->Ocjena,1),

                                        

                                        ),true)',

                 'htmlOptions'=>array('style'=>'width:80px'),

                       

                ),

When I sort or search I lose stars. What I have to do? I understand I have to declare ajaxAfterUpdate, but I don’t know how. I need more detailed explanation. Please help me!

To understand:


 'afterAjaxUpdate'=>'function(id,data){ $(\'div.rating input \').rating(); }', 


div.star-rating input

means input field in


<div class="star-rating">

hi

i was facing same problem while using renderpartial and ajax update i just added below code at the starting of the file and it solved my problem




<script>

$('div#ratinggrid input ').rating();

</script>



hope it will help .


<?php $this->widget('bootstrap.widgets.TbGridView',array(

    'id'=>'customer-grid',

    'type'=>'hover',

    'dataProvider'=>$model->search(),

    'filter'=>$model,

    'afterAjaxUpdate'=>'function(id,data){ $(\'span.starrating input\').rating({readOnly:true}); }',

    ......

    array(

            'name' => 'level',

            'value' => '$this->grid->controller->widget(\'CStarRating\', array(

                    \'name\'=>$data->id,

                    \'value\'=>$data->level,

                    \'minRating\'=>1,

                    \'maxRating\'=>4,

                    \'starCount\'=>4,

                    \'readOnly\'=>true,

                    \'htmlOptions\'=>array(\'class\'=>\'starrating\'),

                ), true);',

                                

            'type' => 'raw',

        ),

    .....



This is how to use CstarRating in CGridView or TbGridView in admin action with ajax search or ajax pagination.

Thanks for help.

I hope the code can help someone.

Hi

In Yiibooster Version 4.0.1

I solved problem by following method


   $this->widget('booster.widgets.TbGridView', array(

            'id' => 'patient-rating-grid',

            'type' => 'striped bordered',          

            'dataProvider' => $dataProvider,

             'afterAjaxUpdate'=>'function(id,data){ $(\'span  > input\').rating({"readOnly":true}); }', 

            'columns' => array(

                array(

                    'header' => 'Date Review',

                    'value' => 'date("F j, Y",strtotime($data->datetime))',

                ), 

                array(

                    'header' => "Doctor's manner",

                    'value' => function($data) {

                        $this->widget('CStarRating', array(

                            'name' => 'doctors_manner' . $data->ratingid,

                            'value' => ceil(intval($data->doctors_manner) * 10 / 100),

                            'minRating' => 1, 'maxRating' => 10, 'starCount' => 5,

                            'readOnly' => true, 'titles' => array(

                                '1' => 'OK', '2' => 'OK', '3' => 'Normal', '4' => 'Normal',

                                '5' => 'Average', '6' => 'Average', '7' => 'Good', '8' => 'Good',

                                '9' => 'Excellent', '10' => 'Excellent'

                            ),

                        ));

                    },

                ),

                array(

                    'header' => 'Wait time',

                    'value' => function($data) {

                        $this->widget('CStarRating', array(

                            'name' => 'wait_time' . $data->ratingid,

                            'value' => ceil(intval($data->wait_time) * 10 / 100),

                            'minRating' => 1, 'maxRating' => 10, 'starCount' => 5,

                            'readOnly' => true, 'titles' => array(

                                '1' => 'OK', '2' => 'OK', '3' => 'Normal', '4' => 'Normal',

                                '5' => 'Average', '6' => 'Average', '7' => 'Good', '8' => 'Good',

                                '9' => 'Excellent', '10' => 'Excellent'

                            ),

                        ));

                    },

                ),

                array(

                    'header' => 'Communication',

                    'value' => function($data) {

                        $this->widget('CStarRating', array(

                            'name' => 'communication' . $data->ratingid,

                            'value' => ceil(intval($data->communication) * 10 / 100),

                            'minRating' => 1, 'maxRating' => 10, 'starCount' => 5,

                            'readOnly' => true, 'titles' => array(

                                '1' => 'OK', '2' => 'OK', '3' => 'Normal', '4' => 'Normal',

                                '5' => 'Average', '6' => 'Average', '7' => 'Good', '8' => 'Good',

                                '9' => 'Excellent', '10' => 'Excellent'

                            ),

                        ));

                    },

                ),

            ),

        ));