Money-formatted numbers in SQLFORM grid

In web2py SQLFORM grid, numbers are shown unformatted and left-aligned. It will be better if the numbers or money values are currency formatted, to make it easier to read. And better yet if those numbers right-aligned in the grid / table. We can use represent in models to do the job, like:

    Field('comm', 'decimal(15,2)', label=T('Comm.')),
    Field('total', 'decimal(15,2)', label=T('Total')),

db.bill.comm.represent = lambda value, row: DIV(moneyfmt(value), _style='text-align: right;') = lambda value, row: DIV(moneyfmt(value), _style='text-align: right;')<span id="mce_marker" data-mce-type="bookmark" data-mce-fragment="1">​</span>

I use function moneyfmt() posted here to format the numbers, shown in grid :

One Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top