antennaio / jquery-bar-rating

jQuery Bar Rating Plugin - minimal, light-weight jQuery ratings.
http://antennaio.github.io/jquery-bar-rating/
MIT License
737 stars 260 forks source link

All records show the same star rating as the very first record #115

Closed chank1980 closed 6 years ago

chank1980 commented 6 years ago

I use initialRating to display the overall star rate for each record, from which is built within a

. I can verify that the rating values are going into the script in chrome DevTools: $(function () { $(".idRate").barrating({ theme: 'fontawesome-stars-o', allowEmpty: true, initialRating: **2.0**, readonly: true }) // $(".idRate").barrating('clear'); //$(".idRate").barrating('destroy'); $(".idRate").barrating('set',0); }); or $(function () { $(".idRate").barrating({ theme: 'fontawesome-stars-o', allowEmpty: true, initialRating: **1.6**, readonly: true }) // $(".idRate").barrating('clear'); //$(".idRate").barrating('destroy'); $(".idRate").barrating('set',0); });

image

I have tried to add 'clear', 'set value' and 'destroy' but none worked. Anyone knows why it renders ok but not showing the correct star rating please?

chank1980 commented 6 years ago

I have cracked the issue of mine. Big thanks to @ChetanGoti who left the sample code in issue #91 and #99 which gave me some ideas to manipulate the script to suit my purpose. I had to wrap ChetanGoti's code in a function to stop it iterate within its won record because the star rating is built on the

, so that the'data-current-rating' would apply to each record and no loop from .each(). image

`$(function () { $('.idRate').each(function (Index, el) { var $El = $(el); $El.barrating({ theme: 'fontawesome-stars-o', allowEmpty: true, initialRating: $El.attr('data-current-rating'), readonly: true })

        })
   })`