Search code examples
grailsgroovygsp

how to sum up values in Grails/GSP


I would like to sum up the total cost in a GSP page ,i get now a list of all values. im using the code below:

<g:each in="${costList}" var="cost">
    <tr>
        <td>${cost.amount}</td>
    </tr>
</g:each>

How can I do that in grails GSP page. thanks!!


Solution

  • This should do it:

    ${costList.sum { it.amount } }