for now the workaround might be manipulating generated html table
like https://groups.google.com/d/msg/web2py/BmbIlkWYZVo/hccT2JQCUp0J
you need to know id of records - so you could get info for calculating
virtual field,
so instead :
fields=[db.product.name, db.product.cost, db.product.quantity,
db.product.virtual_total]
give
fields=[db.product.name, db.product.cost, db.product.quantity,
db.product.id]
and then replace/calculate the 4th column contents:
grid = SQLFORM.grid(query or table, fields=fields)
trs = grid.element("table").elements("tr")
for tr in grid.element("tbody").elements("tr"):
id = int(tr[3][0])
tr[3][0] = str( db.product(id).virtual_total )
ps.: for easier manipulation could use dict notation:
db.product['virtual_total']
db.product(id)['virtual_total']
2013 m. balandis 21 d., sekmadienis 21:49:36 UTC+3, Jurgis Pralgauskis rašė:
>
> Hi, probably, virtual fields can be injected somewhere in:
>
> https://github.com/web2py/web2py/blob/master/gluon/sqlhtml.py#L1931
>
> https://github.com/web2py/web2py/blob/master/gluon/sqlhtml.py#L2242
>
> https://github.com/web2py/web2py/blob/master/gluon/sqlhtml.py#L2322
>
> ps.: For virtual fields, one should know which other fields of table it
> depends on - to .select(..) them for calculations.
> that might need some changes when defining VirtualField ?
> and but these other fields might not need be shown in grid..., so should
> be apart from fields=... argument.
>
> ps.: VirutalFields doesn't have .tablename property - not implemented yet,
> or other reasons?
>
>
> 2013 m. balandis 6 d., šeštadienis 19:33:01 UTC+3, Massimo Di Pierro rašė:
>>
>> I will be fixed asap. I cannot give you a deadline.
>>
>> On Friday, 5 April 2013 19:42:04 UTC-5, Richard wrote:
>>>
>>> I fall on this exact problem, I don't see anything about taht in the
>>> change log of 2.4.4. Is this will be fix soon? I mean SQLFORM.grid support
>>> for virtual field
>>>
>>> THanks
>>>
>>> Richard
>>>
>>>
>>> On Tue, Dec 18, 2012 at 10:32 AM, Massimo Di Pierro <
>>> [email protected]> wrote:
>>>
>>>> Right now grid does not work with virtual fields. There is a pending
>>>> proposal for enhancement to support them.
>>>>
>>>>
>>>> On Tuesday, 18 December 2012 01:03:05 UTC-6, software.ted wrote:
>>>>>
>>>>> Does SQLFORM.grid support adding and display of a virtual field...am
>>>>> getting an exception...my code:
>>>>>
>>>>> db.file_subject_issue.file_**name = Field.Virtual(lambda row:
>>>>> get_file_name(row.file_**subject_issue.file_id))
>>>>> fields = [db.file_subject_issue.file_**id, db.file_subject_issue.date_
>>>>> **created, db.file_subject_issue.file_**name]
>>>>> query =....
>>>>>
>>>>> form = SQLFORM.grid(query,fields=**fields,...)
>>>>>
>>>>> I am getting the error
>>>>>
>>>>> <type 'exceptions.AttributeError'> 'FieldVirtual' object has no
>>>>> attribute '_tablename'
>>>>>
>>>>> 1.
>>>>> 2.
>>>>> 3.
>>>>> 4.
>>>>> 5.
>>>>> 6.
>>>>> 7.
>>>>> 8.
>>>>> 9.
>>>>> 10.
>>>>> 11.
>>>>> 12.
>>>>>
>>>>> Traceback (most recent call last):
>>>>> File "/home/www-data/web2py/gluon/**restricted.py", line 212, in
>>>>> restricted
>>>>>
>>>>>
>>>>> exec ccode in environment
>>>>> File
>>>>> "/home/www-data/web2py/**applications/intranet/**controllers/administration.py"
>>>>>
>>>>> <https://192.168.0.251/admin/default/edit/intranet/controllers/administration.py>**,
>>>>> line 176, in <module>
>>>>>
>>>>>
>>>>> File "/home/www-data/web2py/gluon/**globals.py", line 188, in <lambda>
>>>>>
>>>>>
>>>>> self._caller = lambda f: f()
>>>>>
>>>>>
>>>>> File
>>>>> "/home/www-data/web2py/**applications/intranet/**controllers/administration.py"
>>>>>
>>>>> <https://192.168.0.251/admin/default/edit/intranet/controllers/administration.py>**,
>>>>> line 71, in file_track
>>>>>
>>>>>
>>>>> selectable=False,csv=False , paginate=20, user_signature=False)
>>>>>
>>>>>
>>>>> File "/home/www-data/web2py/gluon/**sqlhtml.py", line 1796, in grid
>>>>>
>>>>>
>>>>> if field._tablename in tablenames]
>>>>>
>>>>> AttributeError: 'FieldVirtual' object has no attribute '_tablename'
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> ..............................**..............................**
>>>>> ...........................
>>>>> Teddy Lubasi Nyambe
>>>>> Opensource Zambia
>>>>> Lusaka, ZAMBIA
>>>>>
>>>>> Cell: +260 97 7760473
>>>>> website: http://www.opensource.org.zm
>>>>>
>>>>> ~/
>>>>> Human Knowledge belongs to the world! - AntiTrust
>>>>>
>>>>> Man is a tool-using animal. Without tools he is nothing, with tools he
>>>>> is all - Thomas Carlyle 1795-1881
>>>>>
>>>>> /~
>>>>>
>>>> --
>>>>
>>>>
>>>>
>>>>
>>>
>>>
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.