Getting the total of the values in a column in a datagrid.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Getting the total of the values in a column in a datagrid.
Hi,
I have a datagrid table to show the contents of an invoice. Each row - item, price, quantity, total, comprises the sales detail of a product. There may be several different products on the invoice, so several rows. My problem is, I want to add the total of the totals in the last column to present a grand total.
It occurs to me that I could do the addition, row by row, outside the dg, adding each total to an outside field then entering the field back into the DG, but one of you guys might know a more elegant way to do it, a single (simple) line of code perhaps ? Hope I've explained it properly. Looking forward to hearing from you..
I have a datagrid table to show the contents of an invoice. Each row - item, price, quantity, total, comprises the sales detail of a product. There may be several different products on the invoice, so several rows. My problem is, I want to add the total of the totals in the last column to present a grand total.
It occurs to me that I could do the addition, row by row, outside the dg, adding each total to an outside field then entering the field back into the DG, but one of you guys might know a more elegant way to do it, a single (simple) line of code perhaps ? Hope I've explained it properly. Looking forward to hearing from you..
Re: Getting the total of the values in a column in a datagrid.
No tricks available here, you will need to make a repeat loop of some sort.
-
- VIP Livecode Opensource Backer
- Posts: 9738
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Getting the total of the values in a column in a datagrid.
CAsba.
Craig
Just what I would do. Use the "dgText" property to get the data out.I could do the addition, row by row, outside the dg,
Craig
Re: Getting the total of the values in a column in a datagrid.
Just a comment - using dgText means you need to extract item x of each line. But that may causes issues down the line if you add/remove/reorder columns as that “x” may shift to a different number.
Another approach is to do the same but with the data in array form (ie dgData instead of dgText). That way you’ll always refer to the key/column by name and order is not important.
Just a thought…
S.
Another approach is to do the same but with the data in array form (ie dgData instead of dgText). That way you’ll always refer to the key/column by name and order is not important.
Just a thought…
S.
Re: Getting the total of the values in a column in a datagrid.
Thanks for that.