default search string in SQL.grid

41 views
Skip to first unread message

Matthew J Watts

unread,
Sep 13, 2018, 7:10:48 AM9/13/18
to web2py-users
Hello all

Is there a way  to pre populate the  'search field' of the SQLFORM.grid? 

For example i can populate fields in an SQLFORM with variables using something like

db.study_data.taxon.default = request.get_vars.tax_species

However, could i do something like?

grid.search.default = request.get_vars.tax_species





Marcelo Huerta

unread,
Sep 13, 2018, 8:36:11 AM9/13/18
to web2py-users
El jueves, 13 de septiembre de 2018, 8:10:48 (UTC-3), Matthew J Watts escribió:
Hello all

Is there a way  to pre populate the  'search field' of the SQLFORM.grid? 



In your URL to the function containing the grid, you can pass the search string in the vars dictionary. Just assign it to the "keywords" key.

Anthony

unread,
Sep 13, 2018, 11:39:50 AM9/13/18
to web2py-users
That's the way to go if you want the grid to show the actual results of the search. If you want the standard set of records but simply want to pre-populate the search box, you can do:

 grid = SQLFORM.grid(db.mytable)
 search_input
= grid.element('#w2p_keywords')
 
if search_input:
     search_input
['_value'] = 'My keywords'

Anthony

Matthew J Watts

unread,
Sep 13, 2018, 12:35:24 PM9/13/18
to web...@googlegroups.com
great, thanks all i´ll give that a go tomorrow!

--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/yohSjabLPCE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthew J Watts

unread,
Sep 17, 2018, 11:34:19 AM9/17/18
to web...@googlegroups.com
thanks that worked a treat! So was that done using jquery? I still have to learn about it

On Thu, Sep 13, 2018 at 5:39 PM Anthony <abas...@gmail.com> wrote:
--
Reply all
Reply to author
Forward
0 new messages