This topic is locked
[SOLVED]

 rating question

3/13/2018 8:35:29 AM
PHPRunner General questions
C
cristi author

I'm trying to implement THIS rating plugin in my database. Basically I have already inserted numbers from 1 to 5 and i use the plugin to convert them to stars. On add, view and edit pages everything is O.K. but I have problems with the List page.
I know that I can't use getValue() on list page so I used this on the javascript onload event in the list page:

var items=[];
$('#tabel tbody tr td:nth-child(11)').each( function(){



items.push( $(this).text() );

});
var i;

for (i = 0; i < items.length; ++i) {


$(function () {



$('.rating').rateYo({

rating: items[i],

starWidth: "20px",

readOnly: true

});



});

}


where "tabel" is the table id, "rating" is a custom class that I added to the column that contains the numbers used for rating.

The problem is that the plugin gets the value from the first cell of the column and use it on all the cells of the column so if the first value on the column is 4 than all the cells in that column are populated with four stars...Can anyone help me see where am I wrong here???

admin 3/13/2018

You need to remember that there are two types of plugins, Edit plugin and View plugins. Edit plugins are designed to work on Add/Edit pages while View plugins work on List/View pages. If you take a look at Rating plugin in our marketplace you will find that it comes as both Edit and View plugin: https://xlinesoft.com/marketplace/products_view.php?editid1=5
In either case you do not need to use getValue() in either plugin, there are other ways to access the current value of the field. Please check this article for more info:

https://xlinesoft.com/phprunner/docs/how_to_create_your_own_edit_control.htm

C
cristi author 3/13/2018



You need to remember that there are two types of plugins, Edit plugin and View plugins. Edit plugins are designed to work on Add/Edit pages while View plugins work on List/View pages. If you take a look at Rating plugin in our marketplace you will find that it comes as both Edit and View plugin: https://xlinesoft.com/marketplace/products_view.php?editid1=5
In either case you do not need to use getValue() in either plugin, there are other ways to access the current value of the field. Please check this article for more info:

https://xlinesoft.com/phprunner/docs/how_to_create_your_own_edit_control.htm


Demo page is not working...
The answer for anyone interested:
It seems that I targeted all the elements with the same class every time in the loop, I need to select elements by index - eq(i) - and execute the loop for every element with the increment index.
So:
for (i = 0; i < items.length; ++i) {

$(function() {

$('.rating').eq(i).rateYo({

rating: items[i],

starWidth: "20px",

readOnly: true

});

});

H
headingwest 3/14/2018

+1 to the xlinesoft star rating plugin, I bought it and it works well.