formatting a field in SQLTABLE

21 views
Skip to first unread message

Vlad

unread,
Aug 24, 2020, 1:43:15 AM8/24/20
to web2py-users
I've got the rows to be displayed in a table:

        rows = db(query).select(db.orders.total.sum().with_alias('Total'), ...............)

and using 

         SQLTABLE(rows)

to show the data. 

How can I format this total.sum() in the SQLTABLE? More specifically, this total is the total amount in cents, and I need to display it in dollars, i.e. divide by 100 and append with '$'. 

It's easy to do it if using TABLE and iterating over rows, but SQLTABLE is pretty convenient to use, so I'd like to stick with it. 

Is there a way to customize the fields like this in SQLTABLE ?




Annet

unread,
Aug 24, 2020, 3:39:49 AM8/24/20
to web2py-users
Maybe use the represent attribute in the field constructor

db.table.field.represent = lambda val, row: function())

and use:

locale.format('%10.2f', val, grouping=True)


Best,

Annet
Op maandag 24 augustus 2020 om 07:43:15 UTC+2 schreef Vlad:
Reply all
Reply to author
Forward
0 new messages