Thanks Niphlod, based on that I worked it out. For us mortals, here's how I 
did it. This is at my level of understanding, not up to one-liners yet :) 

The view linked to the menu the user clicks on LOADs the sqlform grid 
controller like so: 

{{=LOAD('default','order_import_status.load',ajax=True,target='orderform')}}

and the .load view is simply
{{=form}}

the controller function 
order_import_status()

sets up an SQLFORM.grid. Mine is read only. The SQLFORM.grid has a button 
which invokes the web2py ajax() javascript function. Its job is to update 
the database and reload the grid.

After updating the database, this controller uses javascript 
web2py_component() function to reload the .load view. To update the 
database, the ajax-responding controller needs the row id. 
The controller returns javascript which reloads the component via a URL, 
and to maintain the user's search terms, this URL needs to include the 
search keywords. So the ajax-responding controller needs to receive the 
keywords in order to add it to the URL which reloads the grid.

(When the user enters search terms, the controller which displays the 
SQLFORM.grid is re-invoked, and this time request.vars.keywords will have a 
value). 

So this is the controller function which responds to the SQLFORM.grid LOAD, 
now modified to capture the search keywords and preseve them in the onclick 
used by the ajax javascript:

def order_import_status():
    #order status db is updated by the prescan_orders
    #dbg.set_trace()
    keywords = request.vars.keywords 
    
    grid = SQLFORM.grid(db.order_status,user_signature=False,editable=False,
deletable=False,details=False,maxtextlength=60,paginate=100,
                        orderby=db.order_status.message|~db.order_status.
order_number,
                        links = [lambda row: INPUT(_name='toggle',_type=
"submit",_value="Toggle Import",
                                _onclick="ajax('%s',[] ,':eval')" % URL(
'toggle_order_import',args=[row.id],vars=dict(keywords=keywords)))])
    # links = [lamba row: 
INPUT(_name='toggle',type="submit",_value="Toggle"+row.id)]
    return dict(form=grid)

(actually, it should not add vars if keywords == None)

when the links button is clicked, the onlick function uses ajax() which 
sends back to web2py the row ID, and the keywords argument.
My onclicks function is obviously toggle_order_import()  (in the default 
controller) 
and it does this:

keywords = request.vars.keywords  # we do nothing with this except to send 
it back
...  #here be the database updating 
...
url_back = URL('order_import_status.load',vars=dict(keywords=keywords))
return 'web2py_component("%s","orderform");' % url_back


-- 

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