Formatting the Output of the SUM workaround

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
kmullins
Posts: 10
Joined: 2023-12-10 16:44
Location: Seattle, WA USA

Formatting the Output of the SUM workaround

Post by kmullins » 2023-12-18 19:04

In the post SUM lookup column ? an excellent solution for using the hooks folder to add a SUM to a lookup field was shown, and I have been able to make it work, except I would like to format the output in US dollars, and I can't figure out the best way to do it.

Thanks in advance for any assistance.

Code: Select all

			case 'tableview':
				$sum=sqlvalue("SELECT sum(Donations.Amount) from Supporters, Donations where Supporters.ID = Donations.SupporterID");
				$header="<%%HEADER%%><script type=\"text/javascript\">
							\$j(function(){
								\$j('td.Supporters-TotalDonated').last().text(".$sum.").addClass('text-right');
							});
					</script>";
				break;
Screenshot 2023-12-18 104845.png
Screenshot 2023-12-18 104845.png (42.24 KiB) Viewed 5263 times
I know enough to be dangerous but not enough to be effective.
AppGini 24.10 rev 1579

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Formatting the Output of the SUM workaround

Post by pbottcher » 2023-12-31 13:27

Hi,

you can try

Code: Select all

case 'tableview':
	$sum=sqlvalue("SELECT sum(Donations.Amount) from Supporters, Donations where Supporters.ID = Donations.SupporterID");
	$header="<%%HEADER%%><script type=\"text/javascript\">
				\$j(function(){
					\$j('td.Supporters-TotalDonated').last().text(parseFloat(".$sum.",2).toLocaleString('en', { style: 'currency', currency: 'USD', useGrouping: true })).addClass('text-right');
				});
		</script>";
	break;
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

kmullins
Posts: 10
Joined: 2023-12-10 16:44
Location: Seattle, WA USA

Re: Formatting the Output of the SUM workaround

Post by kmullins » 2024-02-02 22:09

Thanks for the idea. unfortunately, I couldn't get it to work. Any time I try any formatting, the field goes blank, so I am just going to keep it without the $.
I know enough to be dangerous but not enough to be effective.
AppGini 24.10 rev 1579

jfischer
Posts: 24
Joined: 2022-11-19 16:07
Location: Austria
Contact:

Re: Formatting the Output of the SUM workaround

Post by jfischer » 2024-02-04 13:48

Hello Kmullins

Formatting as $ goes to Data Format to set. He also takes care of that in total.

Grüße Josef
Attachments
bild-1.png
bild-1.png (155.29 KiB) Viewed 1477 times

kmullins
Posts: 10
Joined: 2023-12-10 16:44
Location: Seattle, WA USA

Re: Formatting the Output of the SUM workaround

Post by kmullins » 2024-02-07 06:09

Thanks jfischer,

Unfortunately, that field is a calculated field, and I am using the following formula to format the calculation.

Code: Select all

SELECT CONCAT('$', FORMAT(COALESCE(SUM(`Payments`.`PaymentAmount`), 0.0), 2)) AS `Total`
FROM `Registrations`
LEFT JOIN `Payments` ON `Payments`.`RegID`=`Registrations`.`ID`
WHERE `Registrations`.`ID`='%ID%'
If I set the data type for that field to currency, that field turns to $0.00 instead of the calculated value.

Thanks though.
I know enough to be dangerous but not enough to be effective.
AppGini 24.10 rev 1579

Post Reply