only whole table search instead granular by field in grid?

81 views
Skip to first unread message

Alex Glaros

unread,
Feb 25, 2015, 1:10:33 AM2/25/15
to web...@googlegroups.com
is there a way to prevent granular field-specific search in grid?

just want the top-level search (that searches all fields) and not the drop down that let's user choose which fields to search

thanks

Alex Glaros

Anthony

unread,
Feb 25, 2015, 2:52:16 PM2/25/15
to web...@googlegroups.com
One simple option is just to disable the Javascript that shows the drop down:

    search_input = grid.element('#w2p_directory_keywords')
    search_input
and search_input.attributes.pop('_onfocus')

You can also create your own search widget (e.g., a simple form with an input and submit button) and pass it as the "search_widget" argument to the grid.

Finally, by default, the grid will search all searchable fields for the keywords. If you want some other behavior (e.g., limit search to particular fields), you can pass your own search function to the grid via the "searchable" argument.

Anthony

Alex Glaros

unread,
Feb 25, 2015, 4:53:37 PM2/25/15
to
thanks Anthony,

Javascript didn't work - where does it go?  Tried both in <script> within html page, and in controller but didn't do anything.

below works but is it a good way to write search?

(1) First create regular full query that shows in default results (all).
(2) Then within the "form", get search_term, and recreate query with that additional filter.

optional, but how would you write the "clear" button?

Alex

## Regular default results user sees on entering the web page. No filter.
  my_connection_requests_i_sent_query = ((db.Role.superObjectID == db.auth_user.superObjectID) & (auth.user_id != db.auth_user.id) & (db.Role.relationshipID == db.Relationship.id) & (db.Relationship.relationshipType == 6) & (db.Relationship.relationshipType == db.RelationshipType.id) & (db.Role.roleType == db.RoleType.id) & (db.Role.created_by == auth.user_id))  
    form  = SQLFORM.factory(Field('key')).process()
   if form.accepted and form.vars.key:
       search_term = form.vars.key  
                ## below is search plus has new search_term filter
       my_connection_requests_i_sent_query = ((db.Role.superObjectID == db.auth_user.superObjectID) & (auth.user_id != db.auth_user.id) & (db.Role.relationshipID == db.Relationship.id) & (db.Relationship.relationshipType == 6) & (db.Relationship.relationshipType == db.RelationshipType.id) & (db.Role.roleType == db.RoleType.id) & (db.auth_user.first_name.contains(search_term)) & (db.Role.created_by == auth.user_id))
   grid = SQLFORM.grid(my_connection_requests_i_sent_query, editable=False, create=False, deletable=False, details=False, searchable=False, fields=[db.auth_user.first_name, db.auth_user.last_name, db.auth_user.id, db.RoleClass.roleType, db.Role.created_on, db.Role.modified_on, db.Role.id, db.RoleType.roleType], links = [dict(header='Cancel connection',  body=lambda row: A('Withdraw my invitation', _href=URL('edit_connection_request', args=row.Role.id), _class='btn'))],  maxtextlengths={'RoleType.roleType':200})


Anthony

unread,
Feb 25, 2015, 5:24:51 PM2/25/15
to web...@googlegroups.com
My code is not Javascript -- it is Python and goes in the controller where you create the grid (note it refers to the "grid"). It disables the Javascript that triggers the drop down, but it is not Javascript code.
Reply all
Reply to author
Forward
0 new messages