What a great new update! Thanks. Just a short question about the rating ctrl:
What I would like to have is that an user selects a whole item (e.g. 3 stars, 4 stars ,...),
but the initial value is a precise interpretation of the average of the ratings.
e.g.
2 polls, rating precision set to "whole item":
person a: 4 stars
person b: 5 stars
--> the average of 4.5 will be displayed as 5 stars (always rounds)
--> I'd favor it would show exact as 4.5 stars
Can I somehow code that the rater selects whole items, the result is displayed exact?
Regards,
phil
6 Answers, 1 is accepted
Currently, the RadRating control does not support this out of the box. However, you can modify the behavior of the control with some javascript. Have a look at the following code fragment:
<telerik:RadRating ID=
"RadRating1"
runat=
"server"
Precision=
"Exact"
Value=
"4.5"
OnClientLoad=
"OnClientLoad"
/>
<script type=
"text/javascript"
>
function
OnClientLoad(sender, args)
{
sender._precision = Telerik.Web.UI.RatingPrecision.Item;
}
Telerik.Web.UI.RadRating.prototype._oldClearPart = Telerik.Web.UI.RadRating.prototype._clearPart;
Telerik.Web.UI.RadRating.prototype._clearPart =
function
(item, originalSize)
{
this
._precision = Telerik.Web.UI.RatingPrecision.Exact;
this
._oldClearPart(item, originalSize);
this
._precision = Telerik.Web.UI.RatingPrecision.Item;
};
</script>
This behavior is already on our TODO list and it will be part of one of our next releases. Basically, our idea is that the rating will display any value that is set through its Value property and the Precision property will only influence the behavior of the control when you rate with the mouse.
Best wishes,
Tsvetie
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Great news. I guess an implementation of this behaviour is the right thing :)
Particularly rounding to an int isn't much trouble...
Thanks and regards,
phil
Hi Telerik,
Since this post is 7 years old, I'm hoping you have implemented the behavior described. However, it is not working for me. If I set the Value="1.5" and Precision="Item", it shows 2 stars selected. It doesn't show 1.5 stars selected unless I set Precision="Exact".
Can you tell me if I still need to use the Javascript hack as illustrated?
Thanks.
Hello Lane,
The Precision property must be set to Exact in order for the exact precision to work: http://demos.telerik.com/aspnet-ajax/rating/examples/overview/defaultcs.aspx.
The original request dates back to 2009 and there hasn't been interest in this since then, so the behavior of the control has not been modified.
That being said, I can suggest you add your request in the Feedback Portal so all our clients can vote and comment on the idea: http://feedback.telerik.com/project/108. If it gains enough traction with the community, product management will add it to the backlog.
In the meantime I can offer a more elegant solution that does not override internal methods, or use hacks, while providing you with more control over the behavior of the rating:
<telerik:RadRating runat=
"server"
ID=
"rr1"
Precision=
"Exact"
Value=
"3.3"
RenderMode=
"Lightweight"
OnClientRating=
"OnClientRating"
></telerik:RadRating>
<script>
function
OnClientRating(sender, args) {
args.set_cancel(
true
);
//prevent the user from rating with precision
sender.remove_rating(OnClientRating);
//detach the handler to avoid endless loop
sender.set_value(Math.round(args.get_newValue()));
//use a rounded version of the user's rating. Or apply any other modification with more sophisticated logic
sender.add_rating(OnClientRating);
//attach the handler again to change the user's behavior
}
</script>
Regards, Marin Bratanov
Telerik by Progress
Thanks Marin.
I found another way of accomplishing this on the server side. I implemented the ItemDataBound event handler and included this code:
RadRating uxRating = e.Item.FindControl(
"uxRating"
)
as
RadRating;
MyObject obj = e.Item.DataItem
as
MyObject;
if
(uxRating !=
null
&& obj !=
null
)
{
if
(obj.AlreadyRated)
{
uxRating.Precision = RatingPrecision.Exact;
}
else
{
uxRating.Precision = RatingPrecision.Item;
}
}
Hello Lane,
This is, of course, an option, but it changes the way the user can interact with the rating, which is why I offered the other workaround. Thus, I have marked both posts as answers to help anyone having the same question in the future.
Regards,
Telerik by Progress