I read that it is not easy to append virtual fields to sqlform.grid...

This thread could be of some helps :

https://groups.google.com/forum/#!topic/web2py/GC0EKaQ8Jjo

Richard

On Tue, Feb 14, 2012 at 5:26 PM, Bruce Wade <[email protected]> wrote:

> Hi,
>
> I have a column I want to show in a SQLFORM.grid that is not a field in
> the database table. The column will add together multiple columns to give a
> total. However I am not sure how to accomplish this.
>
> table:
> db.define_table('bonus_daysummary',
>     Field('create_time', 'datetime', default=request.now),
>     Field('report_date', 'datetime'),
>     Field('distributor_id', 'references distributors'),
>     Field('sponsorbonus', 'decimal(12,2)'),
>     Field('leadbonus', 'decimal(12,2)'),
>     Field('binarybonus', 'decimal(12,2)'),
>     Field('matchingbonus', 'decimal(12,2)'),
>     Field('growingbonus', 'decimal(12,2)'),
>     Field('adviewpayback', 'decimal(12,2)'),
>     Field('adpackcomm', 'decimal(12,2)'),
>     Field('kvalue_deduction', 'decimal(12,2)'),
>     Field('group_management_fee', 'decimal(12,2)'),
>     migrate=False
> )
>
> controller action:
>     class VirtualTotalField(object):
>         def total_price(self):
>             return "$" + str(
>                 self.bonus_daysummary.sponsorbonus +
> self.bonus_daysummary.leadbonus + \
>                 self.bonus_daysummary.matchingbonus +
> self.bonus_daysummary.growingbonus + \
>                 self.bonus_daysummary.adviewpayback +
> self.bonus_daysummary.adpackcomm + \
>                 self.bonus_daysummary.kvalue_deduction +
> self.bonus_daysummary.group_management_fee
>             )
>
>     db.bonus_daysummary.virtualfields.append(VirtualTotalField())
>
>     dailyBonusReport= SQLFORM.grid(
>             (db.bonus_daysummary.distributor_id == distributor.id),
> orderby=[~db.bonus_daysummary.report_date,
> db.bonus_daysummary.distributor_id],  paginate=10, deletable=False,
> editable=False, details=False, csv=True, formname='dailyBonus',
>     )
>
> Now after appending the virtual field how to set its label and have it
> actually displayed in the grid?
>
> --
> --
> Regards,
> Bruce Wade
> http://ca.linkedin.com/in/brucelwade
> http://www.wadecybertech.com
> http://www.warplydesigned.com
> http://www.fitnessfriendsfinder.com
>

Reply via email to