Loss of CStarRating when column is sorted

Hi there ,

Following some awesome support from this forum, I managed to get CStarRating rendered into a column within CGridView. However when the column is sorted I lose the stars and revert back to radio inputs. Is there re initialisation I can do within an afterInit event to bring back those twinkly stars?

Cheers!

See http://www.yiiframework.com/doc/api/1.1/CGridView#afterAjaxUpdate-detail

you should be able to trigger the star rating re-initialization after the grid has been updated.

Thank you for the reply. Would there be anything specific that needs to go in the function, at the moment all the jquery init stuff is being handled automagically by Yii.

After thinking about it, it was embarrassingly simple.




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



:huh:

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. Please help me!

Thank you, talby101. That worked for me - mostly. My stars are readonly and with your code, they were actual input fields after paging.

I couldn’t figure out how to pass the readOnly parameter in .rating(). I tried rating(\‘readOnly\’) and rating(’\readOnly\’, true) and was back to radio buttons.

What DID work for me to keep the "readOnly" aspect was to set the function default prior to calling .rating() without any paramters.




'afterAjaxUpdate'=>'function(id,data){ $.fn.rating.options.readOnly = true; $(\'span.my-rating > input\').rating();}',