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) 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. 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, .......)
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...is used to display new columns which can be links to other pages. The
From the book:
linkslinksargument must be a list ofdict(header='name',body=lambda row: A(...))whereheaderis the header of the new column andbodyis a function that takes a row and returns a value. In the example, the value is aA(...)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, .......)
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.idea.id)))
)]
) lambda row: A('Complete',
_class='btn', _id='btn_complete',
_onclick='return confirm("Complete Order %s? (%s %s)")' % (row.id,
row.shipFirstName,
row.shipLastName),
_href=URL(r=request,f='complete_order',args=[row.id]),
def view_all_suggestions_and_comments(): query = (db.IdeaComment.ideaID==db.Idea.id) & (db.IdeaComment.partyID==db.Party.id) grid = SQLFORM.grid(query, ,links = [dict(header='Virtual Field', body=lambda row: A('Add a comment!',_class="btn btn-mini", _href=URL('comment_on_a_suggestion', vars=dict(filter=row.Idea.id))))]) return dict(grid = grid) What is syntax for TWO or more buttons? I've tried several variations. Would it be two "dict" phrases, or two header phrases separated by commas?
One button will call one function, and the other would call a different function.
thanks,Alex
On Saturday, September 14, 2013 6:56:24 PM UTC-7, Alex Glaros wrote:
--
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
links=dict(purchase_order=[
lambda row:(_get_order_details(row)),
lambda row: A('Duplicate',
_class='button', _href=URL('duplicate_po',args=[row.id])),
lambda row: A('Print', _class='button', _href=URL('print_all',args=[row.id]))
],
other_table=[
lambda row:(_get_something_else(row)),
],),
def view_suggestions(): db.Idea.id.represent = lambda id, r: A('Post shared services idea', _href=URL('add_sharability_info_to_a_suggestion', vars=dict(filter=id)),_class="btn btn-mini") is_owner = (lambda row: row.created_by == auth.user_id) if auth.user else False grid = SQLFORM.grid(db.Idea,editable=is_owner, deletable=is_owner, user_signature=True,fields=[db.Idea.ideaShortSummary,db.Idea.created_by,db.Idea.id], headers={ 'Idea.ideaShortSummary':'Description'}, maxtextlengths={ 'Idea.ideaShortSummary':140},links = [dict(header='Post comment', body=lambda row: A('Post comment',_class="btn btn-mini", _href=URL('comment_on_a_suggestion', vars=dict(filter=row.id))))]), return dict(grid = grid)
grid = SQLFORM.grid(db.Idea,editable=is_owner,
deletable=is_owner,
user_signature=True,
fields=[db.Idea.ideaShortSummary,
db.Idea.created_by,
db.Idea.id],
headers={ 'Idea.ideaShortSummary':'Description'},
maxtextlengths={ 'Idea.ideaShortSummary':140},
links = dict(Idea=[lambda row: A('Post comment',
_class="btn btn-mini",
_href=URL('comment_on_a_suggestion', vars=dict(filter=row.id))
),
lambda row: A('Post comment',
_class="btn btn-mini",
_href=URL('comment_on_a_suggestion', vars=dict(filter=row.id))
),
],
)
)
def view_suggestions(): postComment=db.Idea.id sharedSerices=db.Idea.id ## All variables get populated with db.Ideaid and each represent clause creates href link to a different function postComment.represent = lambda id, r: A('Post comment', _href=URL('comment_on_a_suggestion', vars=dict(filter=id)),_class="btn btn-mini") sharedSerices.represent = lambda id, r: A('Post shared services idea', _href=URL('add_sharability_info_to_a_suggestion', vars=dict(filter=id)),_class="btn btn-mini") is_owner = (lambda row: row.created_by == auth.user_id) if auth.user else False grid = SQLFORM.grid(db.Idea,editable=is_owner, deletable=is_owner, user_signature=True,fields=[db.Idea.ideaShortSummary,db.Idea.created_by,sharedSerices,postComment], headers={ 'Idea.ideaShortSummary':'Description','sharedServices':'Shared Services'}, maxtextlengths={ 'Idea.ideaShortSummary':140}), return dict(grid = grid) def view_all_suggestions_and_comments(): query = (db.IdeaComment.ideaID==db.Idea.id) & (db.IdeaComment.partyID==db.Party.id)
grid = SQLFORM.grid(query, ,links = [dict(header='Virtual Field',
body=lambda row: A('Add a comment!',_class="btn btn-mini",
_href=URL('comment_on_a_suggestion', vars=dict(filter=row.Idea.id))))]) return dict(grid = grid)
mylistoflinks and make it a list (so you can have multiple links):def view_all_suggestions_and_comments(): query = (db.IdeaComment.ideaID==db.Idea.id) & (db.IdeaComment.partyID==db.Party.id)
mylistoflinks = [
dict(header='Virtual Field',
body=lambda row: A('Add a comment!',_class="btn btn-mini",
_href=URL('comment_on_a_suggestion', vars=dict(filter=row.Idea.id)))),
dict(header='Virtual Field',
body=lambda row: A('Add a comment!',_class="btn btn-mini",
_href=URL('comment_on_a_suggestion', vars=dict(filter=row.Idea.id)))),
]
grid = SQLFORM.grid(query, links = mylistoflinks ) return dict(grid = grid)