Try this...
grid = SQLFORM.grid(query,
links = [dict(header='Virtual Field',
body=lambda row: A('Add
a comment!', _href=URL('comment_on_a_suggestion', vars=dict(filter=row.id)))
)]
)
On Friday, 13 September 2013 21:57:28 UTC+1, Alex Glaros wrote:
>
> I tried this but got "lambda requires 2 args, 1 given" error, plus need to
> be able to pass Idea.id parm to the button. How to do that?
>
> grid = SQLFORM.grid(query,links = [dict(header='Virtual
> Field',body=lambda id, r: A('Add a comment!',
> _href=URL('comment_on_a_suggestion', vars=dict(filter=id))))])
>
> On Friday, September 13, 2013 1:33:35 PM UTC-7, villas wrote:
>>
>> Hope this helps...
>>
>> From the book:
>>
>> links is used to display new columns which can be links to other pages.
>> The links argument must be a list of dict(header='name',body=lambda row:
>> A(...)) where header is the header of the new column and body is a
>> function that takes a row and returns a value. In the example, the value is
>> a A(...) helper.
>>
>> Example:
>>
>> linkbtns = [
>> lambda row: SPAN('Mag',_class="label label-success") \
>> if row.status =='Y' else '',
>> lambda row: SPAN('Web',_class="label label-success") \
>> if row.is_active else '',
>> lambda row: A( I('',_class="icon-eye-open")+' View',
>> _href=URL("view",args=[row.id]),
>> _class="btn btn-small"
>> ),
>> lambda row: A( I('',_class="icon-edit")+' Edit',
>> _href=URL("edit",args=[row.id]),
>> _class="btn btn-small"
>> ),
>> lambda row: A( I('',_class="icon-road")+' Map',
>> _href=URL('default','geocoder',args=[
>> 'caclient',row.id],vars={'title':row.business}),
>> _class="btn btn-small"
>> ),
>> ]
>> grid = SQLFORM.grid(....... links=linkbtns, .......)
>>
>>
>>
>>
>> On Friday, 13 September 2013 21:00:56 UTC+1, Alex Glaros wrote:
>>>
>>> How do I add a button "Add a comment!" in every row of a grid? It's a
>>> kind of virtual column.
>>>
>>> The below works, it takes user exactly to the correct row in the next
>>> table, but I use up one of the fields (Idea.id). How do I just create
>>> text/virtual column that doesn't sacrifice existing field?
>>>
>>>
>>> def view_all_suggestions_and_comments():
>>> db.Idea.id.represent = lambda id, r: A('Add a comment!',
>>> _href=URL('comment_on_a_suggestion', vars=dict(filter=id)))
>>> query = (db.IdeaComment.ideaID==db.Idea.id) &
>>> (db.IdeaComment.partyID==db.Party.id)
>>> grid = SQLFORM.grid(query)
>>> return dict(grid = grid)
>>>
>>>
>>> I read the book but need exact syntax for this situation.
>>>
>>> Thanks,
>>>
>>> Alex Glaros
>>>
>>
--
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.