Hi Richard, Thanks so much for your advises. Before i added the represent=... to quotation table, i was able to see the company name (instead of company id) on my grid display, so displaying it wasn't an issue. I was also able to set a search criteria in the search widget e.g. Company Name = XYZ (from dropdown), the search textbook displayed quotation.company='4' next to the Search button in the widget. Only when I typed the company name in the Search textbox and hit the Search button, it didn't find it, but I could search for any string in text or string fields. If this system is for my own use, there is no issue, but for end user, it's very natural that enduser would like to find all the quotations for a single customer by typing the company name in the Search textbook, I wonder if there is a way to do that.
I tried below suggestion with 'represent', it didn't allow me to do what I wanted as described above. Any further input is appreciated. Thanks again On Friday, April 28, 2017 at 1:26:48 AM UTC+8, Richard wrote: > > Hello Rudy, > > I am not sure I understand what you mean by : "I can write an action > select_quote_by_name() to address it" > > But, you sould be able to use "company" reference field representation > like so : > > db.define_table('quotation', > Field('company', 'reference company', > represent=lambda id, row: > db.company(id).company_name if id else T('N/A')), > Field('project_name', requires=IS_NOT_EMPTY()), > Field('quote_amount', 'double', default=0, writable=False)) > > This should show company_name in grid and you should be allow to search > with company name in the search widget. > > Richard > > On Thu, Apr 27, 2017 at 1:03 PM, Rudy <rudy...@gmail.com <javascript:>> > wrote: > >> Hi there, >> >> I have a quotation table which references the company table. When i >> created a SQLFORM.grid, I couldn't use the company_name as keyword in the >> default search widget as company field in the quotation table is integer >> type (id) even though it's displayed as company_name. I can write an action >> select_quote_by_name() to address it, but I wonder if there is any simple >> way to address this matter while I can still leverage the default search >> widget? Thanks in advance! >> >> db.define_table('company', >> Field('company_name', requires=IS_NOT_EMPTY()), >> format='%(company_name)s') >> db.define_table('quotation', >> Field('company', 'reference company'), >> Field('project_name', requires=IS_NOT_EMPTY()), >> Field('quote_amount', 'double', default=0, >> writable=False)) >> >> grid=SQLFORM.grid(db.quotation) >> >> -- >> 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 the Google Groups >> "web2py-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to web2py+un...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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 the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.