I have a channel with a field type used for numbers (called “price”) I want to show on one page all the entries for this channel, and at the end I want to calculate the amount of all values in that field, from all entries and the amount to be updated dynamically with each entry added. It’s that possible? Thanks
There’s no native way to do this with EE. You might be able to do this with Stash ( https://github.com/croxton/Stash ) and variables. However, I’d probably just do this with Javascript.
For a basic example, my template would look something like this:
{exp:channel:entries}
...
<span class="price">{price}</span>
...
{/exp:channel:entries}
Total Sum of Price: <span class="price-total"></span>
And then using jQuery, my Javascript would look like:
var i = 0;
$(".price").each(function () {
i = parseFloat(i) + parseFloat($(this).data("price"));
});
$(".price-total").html(i);
hope this helps.
To not assume anything. If you’re using my example exactly as is,
$( window ).load(function() { ... }
Still not working
This is the template <!DOCTYPE html> <html><head> <title> </title>
<!– jQuery –>
[removed][removed]
</head>
<body>
<div margin:0 auto; width:800px”> <div class=”uk-container uk-container-center”>
{exp:channel:entries channel="test" } {price} {/exp:channel:entries}
Total Sum of Price:
[removed] var i = 0;
$(“.price”).each(function () { i = parseFloat(i) + parseFloat($(this).data(“price”)); });
$(“.price-total”).html(i);[removed] </div> </div> </body></html>
and this is the result:
https://bazesportive.sibiu.ro/site/test
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.