Group Totals

44 views
Skip to first unread message

Jeff

unread,
Sep 5, 2011, 11:24:27 PM9/5/11
to Ruby Reports
I've read through the book, and I understand how to calculate the
total for a group, but what I don't get is how do I put a totals row
at the bottom of each group? I'm running a basic transaction history,
and for each date I'd like to put the sales total at the bottom of
each group.

Also, any insights on how to format a specific column to display as
currency?

Andrew France

unread,
Sep 6, 2011, 3:44:41 PM9/6/11
to ruby-r...@googlegroups.com
On 06/09/11 04:24, Jeff wrote:
> I've read through the book, and I understand how to calculate the
> total for a group, but what I don't get is how do I put a totals row
> at the bottom of each group? I'm running a basic transaction history,
> and for each date I'd like to put the sales total at the bottom of
> each group.

I can't remember if there is a canonical way to do it but a couple of
ideas spring to mind. A Group is a subclass of Table so you could just
iterate over the Grouping and add the total figure as a new row to the
end. It's probably better to iterate over each Group in your formatter
and output the total separately so you can control the display of it
precisely.

> Also, any insights on how to format a specific column to display as
> currency?

This is also technically a display issue where the logic belongs in the
Formatter. You can override individual row output to display as you like
or use Table#change_column to modify the values in place.

Hope that helps. If you have small specific example code you are stuck
with feel free to post that here.

Regards,
Andrew


--
Avito Ltd
Currently in Cambridge, UK (BST)
-------------------
Reg office: 23 Hoadly Road, Cambridge, CB3 0HX.
Company 05946211 registered in England.
-------------------

Jeff Lee

unread,
Sep 6, 2011, 3:54:38 PM9/6/11
to ruby-r...@googlegroups.com
Thanks.  I was wondering this morning if that's what the technique was (vs. some canned group with total type function).  I'll undoubtedly get stuck along the way, so I'll be back  :).



--
You received this message because you are subscribed to the Google Groups "Ruby Reports" group.
To post to this group, send email to ruby-r...@googlegroups.com.
To unsubscribe from this group, send email to ruby-reports+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ruby-reports?hl=en.


Reply all
Reply to author
Forward
0 new messages