links in sqlform.grid

495 views
Skip to first unread message

黄祥

unread,
Sep 20, 2013, 2:19:18 PM9/20/13
to web...@googlegroups.com
hi,

i have an table that contain an upload field for store image, i want to show the image in sqlform grid. i tried to using link for achieve that, it works well (code 1), but there is no header on it, when i put the header (code 2) like describe on the book, it return an error :
TypeError: 'str' object is not callable.

code 1 (work, but no header):
def product():
links=[lambda row: A(IMG(_src=URL('download', args=row.image), _width=50, _height=50), _href=URL('download', args=row.image))]
grid=SQLFORM.grid(db.product, 
  links=links)
  #links=dict(header='image',body=[lambda row: A(IMG(_src=URL('download', args=row.image), _width=50, _height=50), _href=URL('download', args=row.image))]))
  #links=dict(header='image',body=lambda row: A(IMG(_src=URL('download', args=row.image), _width=50, _height=50), _href=URL('download', args=row.image))))
return locals()

code 2 (not work return an error : TypeError: 'str' object is not callable.):
def product():
links=[lambda row: A(IMG(_src=URL('download', args=row.image), _width=50, _height=50), _href=URL('download', args=row.image))]
grid=SQLFORM.grid(db.product, 
 #links=links)
  #links=dict(header='image',body=[lambda row: A(IMG(_src=URL('download', args=row.image), _width=50, _height=50), _href=URL('download', args=row.image))]))
  links=dict(header='image',body=lambda row: A(IMG(_src=URL('download', args=row.image), _width=50, _height=50), _href=URL('download', args=row.image))))
return locals()

how can i show the image with the header in sqlform.grid?

thanks and best regards,
stifan

Niphlod

unread,
Sep 20, 2013, 2:59:19 PM9/20/13
to web...@googlegroups.com
taken directly from http://web2py.com/books/default/chapter/29/07/forms-and-validators#SQLFORM.grid-and-SQLFORM.smartgrid

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.

so, links is a list of dicts .... [dict(), dict()]

黄祥

unread,
Sep 20, 2013, 8:52:59 PM9/20/13
to web...@googlegroups.com
thank you so much, it works as expected now.

best regards,
stifan

Laurent Lc

unread,
Oct 5, 2015, 9:54:09 AM10/5/15
to web2py-users
Could tou give the good code because it does not run for me and i do not see what's going wrong
cheers

黄祥

unread,
Oct 5, 2015, 7:59:55 PM10/5/15
to web2py-users
e.g.
def company():
table = db.company
links = [dict(header = T('Logo'), 
 body = lambda row: A(IMG(_src = URL('default', 'download', args = row.logo), 
_width = 100, _height = 100), 
_href = URL('default', 'download', args = row.logo) ) ) ]
grid = SQLFORM.grid(table, links = links)
return locals()

best regards,
stifan
Reply all
Reply to author
Forward
0 new messages