edit or delete child or detail table on SQLFORM.grid with left join

75 views
Skip to first unread message

黄祥

unread,
Mar 3, 2017, 6:52:30 PM3/3/17
to web2py-users
is it possible to edit or delete child or detail table on SQLFORM.grid with left join?
i've tried before it seems the edit is for the first table (parent or header), the child or detail table cannot be edited or deleted with left join in SQLFORM.grid.
e.g.
def report_production_result():
table_header = db.production_result_header
table_detail = db.production_result_detail

orderby = ~table_header.id
left = table_detail.on(table_header.id == table_detail.production_result_no)
fields = [
 # header
 table_header.id, table_header.production_result_no, table_header.production_result_date, 
 table_header.shift, table_header.origin, table_header.status, 
 # detail
 table_detail.stock, table_detail.quantity]
grid = SQLFORM.grid(table_header, fields = fields, left = left, orderby = orderby)
return locals()

thanks and best regards,
stifan

Massimo Di Pierro

unread,
Mar 20, 2017, 10:41:18 AM3/20/17
to web2py-users
Unfortunately not out of the box. You need a custom button that does a ajax query. 

Fabiano Almeida

unread,
Mar 20, 2017, 12:02:47 PM3/20/17
to web...@googlegroups.com
Thanks Massimo, I will try this.

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

黄祥

unread,
Mar 20, 2017, 7:38:52 PM3/20/17
to web2py-users
could anyone give an example to custom button in grid that does an ajax query?

another question is oot :
what is the best practice to define table for transaction that separated for header and detail? 
when use header and detail it good for normalisation but not good in operational, in case want to edit or delete it, when using 1 table for header and detail, the data is for header is repeated in the rows.

thanks and best regards,
stifan

Massimo Di Pierro

unread,
Mar 21, 2017, 2:11:31 PM3/21/17
to web2py-users
For example:


db.define_table('thing',Field('name'),Field('checked','boolean',readable=False))

def index():
   grid = SQLFORM.grid(db.thing, links=[lambda row: A('check',_onclick="jQuery.post('%s')" % URL('check',args=row.id))])
   return dict(grid=grid)

def check():
  db(db.thing.id==request.args(0)).update(checked=True)

黄祥

unread,
Mar 21, 2017, 5:00:05 PM3/21/17
to web2py-users
a, i c, thank you so much for your example massimo, that's why my old code not work because i'm using _href
e.g.
def index():
grid = SQLFORM.grid(db.thing, links=[lambda row: A('check',_onclick="jQuery.post('%s')" % URL('check',args=row.id))])
#grid = SQLFORM.grid(db.thing, links=[lambda row: A('check',_href=URL('check',args=row.id) ) ] ) # not work use _onclick = jQuery.post()
return dict(grid=grid)

Massimo Di Pierro

unread,
Mar 21, 2017, 8:06:45 PM3/21/17
to web2py-users
The A helper also has a A(..., callback=URL()) that posts to the callback. But I think _onclick is more explicit.
Reply all
Reply to author
Forward
0 new messages