I want to show rating based on the returned value of an object method. JS function - returns an html that contains amount of stars based on a parameter. Parameter - digit up to 5. I get it from calling employee.getUser().getAvgGrade().
Here is a table I have
<table>
<thead>
<tr>
<th>Name</th>
<th>Rating</th>
<th>Schedule</th>
</tr>
</thead>
<tbody>
<tr th:each="employee:${employees}">
<td th:text="${employee.getUser().getFullName()}"></td>
<td th:text="${employee.getUser().getAvgGrade()}"></td>
<td th:text="${employee.getTimeBegin() + ' - ' + employee.getTimeEnd()}"></td>
</tr>
</tbody>
</table>
Here is a JS function that returns HTML
function star(rate) {
var starHTML = '';
var rate = parseInt(rate);
var increment = 0;
var max = 5;
while(increment < rate) {
starHTML += '<i class="material-icons orange">grade</i>';
increment++;
}
while(max > rate) {
starHTML += '<i class="material-icons gray">grade</i>';
max--;
}
return starHTML;
};
CSS for stars
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet">
I want to call this function with the integer from getAvgGrade() ( second th:text ) and place the html it returns as th:text ( so the cell holds the stars ).
