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?


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();   }', 


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











                                        "ratingStepSize" => 0.5,











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();}',