Hi,
take a look to the manual:
http://www.web2py.com/books/default/chapter/29/07/forms-and-validators#SQLFORM-grid
Multiple grids per controller function
Because of the way grid works one can only have one grid per controller
function, unless they are embedded as components via LOAD. To make the
default search grid work in more than one LOADed grid, please use a
different formname for each one.
On Tue, Jul 7, 2015 at 10:59 AM, Prasad Muley wrote:
> Hi,
>
> I have a SQLFORM.grid which displays information about employee
> table. Every employee may have multiple addresses.
> So I have to display multiple address in another grid (address grid)
> inside edit form of the employee grid.
>
>
> *models/db.py*
>
> db.define_table('employee',
> Field('fname', 'string', label=T("First Name"),
> required=True),
> Field('lname', 'string', label=T("Last Name"),
> required=True),
> Field('email', requires=IS_EMAIL()),
> format='%(email)s')
>
> db.define_table('address',
> Field('employee', db.employee),
> Field('Address', 'text'))
>
> *controllers/default.py*
>
> def _validate_emp_records(form):
> error_exist = False
> if not form.vars.fname:
> form.errors.fname = T("Enter First Name")
> error_exist = True
>
> if not form.vars.lname:
> form.errors.lname = T('Enter last name')
> error_exist = True
>
> return not error_exist
>
>
> @auth.requires_login()
> def index():
> """
> example action using the internationalization operator T and flash
> rendered by views/default/index.html or views/generic.html
>
> if you need a simple wiki simply replace the two lines below with:
> return auth.wiki()
> """
> query = (db.employee.id > 0)
> emp_grid = SQLFORM.grid(query, showbuttontext=False, csv=False,
> deletable=False)
> address_grid = None
>
> if request.args(0) == 'edit':
> form = emp_grid.update_form
> emp_id = request.args(2)
> address_query = (db.address.employee == emp_id)
> # show all address in edit form of employee
> address_grid = SQLFORM.grid(address_query, deletable=False,
> showbuttontext=False, csv=False)
>
> if form.process(onvalidation=_validate_emp_records).accepted:
> session.flash = T('Updated %s' % form.vars.id)
> redirect(URL('default', 'index'))
> elif form.errors:
> response.flash = T("form has errors")
>
> if request.args(0) == 'view':
> form = emp_grid.view_form
>
> if request.args(0) == 'new':
> form = emp_grid.create_form
>
> return dict(emp_grid=emp_grid, address_grid=address_grid)
>
>
> *views/default/index.html*
>
>
> {{extend 'layout.html'}}
>
> {{=emp_grid}}
>
> {{ if address_grid: }}
> {{ =address_grid}}
> {{ pass }}
>
>
> Here,
> It shows two edit forms whenever I click on edit icon. [See
> attachment edit_records.png]
>
> Is it possible to display SQLFORM.grid inside view of another SQLFORM.grid?
>
>
> --
> 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.
>
--
Massimiliano
--
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.