Thank you, Anthony!

I have found the same solution after reading the source code.
Maybe this tip is worth making mention of it in the book?

2016-05-24 17:16 GMT+02:00 Anthony <abasta...@gmail.com>:

> Rather than using the "fields" argument, to suppress a field in the grid,
> just set its "readable" attribute to False (before creating the grid):
>
> db.t1.bb.readable = False
> grid = SQLFORM.grid(db.t1)
>
> Anthony
>
>
> On Tuesday, May 24, 2016 at 8:44:53 AM UTC-4, mweissen wrote:
>>
>> Let's say I have table with two integer fields and one virtual field:
>>
>> db.define_table('t1',
>>     Field('aa','integer'),
>>     Field('bb','integer'),
>>     Field.Virtual('ab', lambda row: row.t1.aa+row.t1.bb),
>>     )
>>
>>
>> The SQLFORM.grid works fine:
>>
>> def ab():
>>     grid=SQLFORM.grid(db.t1,
>>            fields=(db.t1.aa, db.t1.bb, db.t1.ab),
>>            user_signature=False,
>>          )
>>     return locals()
>>
>>
>> ​But I do not want to show the column bb and I tried:
>>
>> ​def ab():
>>     grid=SQLFORM.grid(db.t1,
>>            fields=(db.t1.aa, db.t1.ab),
>>            user_signature=False,
>>          )
>>     return locals()
>>
>>
>> and - of course - now I get a "key error", because the virtual field
>> cannot access db.t1.bb.
>>
>> I understand, that the fields parameter decides, which columns should be
>> displayed AND which columns could be used in expressions, e.g. in a
>> lambda-function. But these columns could be different.
>>
>> My question:
>> How can I use both columns in a function, but without displaying both
>> columns in the grid?
>>
>> Or simple: is it possible to suppress a column in the grid which has been
>> selected in the fields parameter?
>>
>> Regards Martin
>>
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to