Of course. Your function creates and returns a grid only when the form is 
submitted -- otherwise it never gets through your form.accepts test. You 
might be better off using the built-in grid search functionality. You can 
modify the search to only search the lname field. You just have to add some 
logic to make sure no records are shown on the initial page load (before a 
keyword is entered in the search box):

    query = db.consumer if request.vars.keywords else db.consumer.id < 0
    grid = SQLFORM.grid(query, searchable=lambda f, k: db.consumer.lname ==k
)
    search_input = grid.element('#w2p_keywords')
    search_input and search_input.attributes.pop('_onfocus')

db.consumer.id < 0 will return no records, which will happen on the initial 
page load (before any keywords have been entered). The "searchable" 
argument to the grid can be a callable that takes a list of fields and a 
keywords string and returns a query (they above simply checks for records 
with lname equal to the keywords entered). The last two lines simply 
disable the Javascript search widget in the grid, so all you get is a plain 
text box. With the above, you don't need your separate form to enter the 
lname.

Anthony


On Tuesday, December 31, 2013 1:34:06 PM UTC-5, Keith Planer wrote:
>
> def patient_lookup():
>     db.consumer.id.readable=False
>     var = request.args(0)
>     grid = []
>     links=[lambda row: A('Note',_href=URL('default', 'notes',args=[row.id
> ])),
>            lambda row: A('Diagnosis',_href=URL('default', 
> 'diagnosis_lookup',args=[row.id])),
>            lambda row: A('Orders',_href=URL('default', 'phys_order',args=[
> row.id]))]
>     form = FORM("Last Name: ",INPUT(_name='lname'),INPUT(_type='submit'))
>     if form.accepts(request.vars, session):
>         query=(db.consumer.lname.like(form.vars.lname+'%'))
>         grid=SQLFORM.grid(query, deletable=False,  searchable=False,create
> =False, csv=False, paginate=5, links=links, user_signature=True, headers={
> '...'})
> return dict(form=form, grid=grid)
>
>
>
>
> The behavior its showing is that when I hit submit, it'll bring back the 
> first page of records, When I hit the link for another page, the grid will 
> just show the [] that I have on the 4th line. I would get rid of it but the 
> page breaks without it.When I hit the submit button again, the grid will 
> show the page that I wanted to see before. I hit the link for another page 
> and just "[]" again. And so on....
>

-- 
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.

Reply via email to