sqlform.grid search numeric fields

27 views
Skip to first unread message

Scott Hunter

unread,
Dec 3, 2016, 9:27:39 AM12/3/16
to web2py-users
When using the basic (as opposed to advanced) search function of an SQLFORM.grid, it only appears to look in text fields, such that if I enter a number, it doesn't find any matches unless that number appears in a text field (even if that field is not one of the ones displayed in the grid).

Is this intentional?  Short of using the advanced search, is there a way to search numeric fields?

- Scott

Anthony

unread,
Dec 3, 2016, 10:56:14 AM12/3/16
to web2py-users
You can customize the search functionality by providing (a) a custom widget via the "search_widget" argument (it takes a list of searchable fields and a URL and should return a search form) and/or (b) a custom search query builder via the "searchable" argument (it takes a list of searchable fields and the keyword string from the search form and should return a DAL query object).

By default, the query builder is gluon.sqlhtml.SQLFORM.build_query -- so check that out to see how it works.

When you set advanced_search=False, all it does is disable the Javascript functionality of the search widget that facilitates the advanced search syntax (you can still manually enter advanced search syntax, and you will get an advanced search query). The build_query method looks for quotes in the keyword string and if found, it calls pydal.helpers.methods.smart_query to generate the query. Otherwise, it just does a basic search across text fields (which is what you are getting).

Anthony
Reply all
Reply to author
Forward
0 new messages