CStarRating and CListView problem


in my case, i have the "allowEmpty" property set to false, so with this code:

$("span[id^=\'rating\'] > input").rating();

the jquery will process the star’s with the default parameters, so,

i used this code:

$("span[id^=\'rating\'] > input").rating({\'required\':true});

you must put the parameters in the jquery function call ;)

(Sorry for any language mistake ;) )


I had a problem with CStarRating in CListView with ordering headers (such sort by date), and apart from on the original loading there was no way to get it working (neither with the id "#qwerty" trick, because the whole page was sent again and nor rendering the order as desired.

My bulldozer solution was to refactor the CStarRating::rendeStars() function to display gif images when the widget is readOnly, rather than the disguised radiobutton referencing some images through the css…


			for($value=$this->minRating, $i=0;$i<$inputCount; ++$i, $value+=$this->ratingStepSize)








				echo CHtml::radioButton($name,!strcmp($value,$selection),$options) . "\n";



			$nb_s = floor($selection/2.0);

			$nb_s_half = fmod($selection/2.0,1.0);


				echo CHtml::image('./images/star_2.gif','star2');


				echo CHtml::image('./images/star_1.gif','star1');


				echo CHtml::image('./images/star_0.gif','star0');


The only requirement is that you have the stars image below your public web folder (in my case html_public/images

I have attached the images as gif with transparent background for convenience…

This solved it for though it is a bit rough…

For sure the star images included could be put in the assets folder of the CStarRating widget and referenced properly in the renderStars function… to make it cleaner

Regards Emmanuel

In case anyone else has the same issue as I did - it is important to set unique ‘name’ for each widget if you have multiple ones (e.g. using CListView) on the page. Otherwise all the stars would be rendered right next to each other where the first widget is placed, assuming you have processOutput (4th parameter of renderPartial) set to false. If you set this parameter to true, stars would be rendered fine, but it breaks all other jQuery plugins since it loads core jQuery libraries multiple times.


    'model' => $rating,

    'id' => 'itemRating-'.$data->id,

    'name' => 'itemRating-'.$data->id,  // NB: important to set unique id for multiple widgets to be rendered independantly

    'attribute' => 'value',

    'starCount' => 10,

    'readOnly' => false,

    'resetText' => 'Remove rating for this item',

    'starWidth' => 3,

    'callback' => $ratingSubmitCallback,

)); ?>

You are a life saver, Thank you

well done …graet forum


When I use

'id' => '#tutor',

in CListView, it have an error “Uncaught Error: Syntax error, unrecognized expression: ##tutor” “jQuery(’##tutor’).yiiListView({‘ajaxUpdate’:[’#tutor’],‘ajaxVar’:‘ajax’,‘pagerClass’:‘pagination-container’,‘loadingClass’:‘list-view-loading’,‘sorterClass’:‘sorter’,‘enableHistory’:false});