Grid - limit searches to specified fields not whole tables

72 views
Skip to first unread message

Matthew J Watts

unread,
Jul 7, 2017, 8:42:37 AM7/7/17
to web...@googlegroups.com

Hi all

 

I’m having problems trying to tailor the grid to my needs

I've set up a grid to query my db and it retrieves the data successfully, great!

 

Example: def gridquery():

    grid = SQLFORM.grid((db.MAIN.TaxonID == db.TAXON.TaxonID), field_id = db.MAIN.MainID, fields=[db.TAXON.TaxonName, db.TAXON.CommonName, db.TAXON.TaxonomicPhylum])

    return locals() 

 

However, the search box contains all of the columns in all of the connected tables.  I want to limit the searches only to the fields i have specified e.g. 'fields=[db.TAXON.TaxonName, db.TAXON.CommonName, db.TAXON.TaxonomicPhylum])'. 

 

1.      I've tried to do a few things i.e.  setting the unwanted search fields to 'writable = False & readable = False'

2.       also tried this method [setattr(f, 'readable', False) for f in mydb if f.name not in ('mydb.field')]

 

However, this limits the query results - i want to include all the tables fields in the query results, just not in the searches. 

 

Does anyone have any suggestions? As I understand I might need to build a custom widget, at my current level this seems rather complicated,is there a simpler work around?.

 

Thanks!

Anthony

unread,
Jul 7, 2017, 10:33:20 AM7/7/17
to web2py-users
I think you'll need a custom search widget and/or search function (the latter via the "searchable" argument). For details on how the current default search widget is constructed, see https://github.com/web2py/web2py/blob/89832479fccf6bb2d0ef19427bff2ee7f5347807/gluon/sqlhtml.py#L2618. Note, it is built based on the SQLFORM.search_menu static method.

Feel free to open an issue or make a pull request.

Anthony

Matthew J Watts

unread,
Jul 7, 2017, 10:53:54 AM7/7/17
to web2py-users
Ok thanks Antony i'll look into it, this looks like it could take some time!!
Reply all
Reply to author
Forward
0 new messages