Thanks Leonel, I will go with this.
Greetings.
El 14/08/17 a las 11:34, Leonel Câmara escribió:
Here's one way to do it. Note that when I start having this kind of
problems I usually stop using the grid and make a custom solution.
In the grid, the searchable argument, can be a function. In that case
it gets the fields and keywords and its responsibility is to generate
and return a query. You can disable advanced_search and then only have
a search field. Then you will have a searchable function which will
detect if one of the keywords entered in the search is a date, if that
is the case then you will make a query where only records from that
date are acceptable.
Your controller function would be something like this:
|
defmygrid():
importdatetime
defsearchable(fields,keywords):
query =db.my_table.id >0:
forkeyword inkeywords:
date =None
try:
date =datetime.datetime.strptime(keyword,'%Y-%m-%d')
exceptValueError:
pass
ifdate:
query &=db.my_table.created_on ==date
else:
# this is just an example
query &=db.my_table.name.like('%'+keyword
+'%',case_sensitive=False)
returnquery
return{'grid':SQLFORM.grid(db.my_table,searchable=searchable,advanced_search=False)}
|
--
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
<mailto:web2py+unsubscr...@googlegroups.com>.
For more options, visit *MailScanner ha detectado un intento de fraude
en la siguiente p�gina web "groups.google.com". /No/ conf�e en esta
p�gina web:* https://groups.google.com/d/optout
<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.