sqlformfactory smartgrid just search field

128 views
Skip to first unread message

Ron Chatterjee

unread,
Mar 5, 2015, 12:26:32 PM3/5/15
to web...@googlegroups.com
I like the way the search field shows up using smartgrid in web2py. But I dont want the table to b listed below because I want to customize the table display. Does anyone know if there is way to display just the search box using smartgrid without displaying the table underneath? I know there is a way to create a search box using "like". But for now I am okay with the search box that is generated out of grid (form factory). And once the query is post, I want to redirect to the table. Any thoughts about how to display the search box without the table underneath. Then for the first cut, I could use this search box real quick on the page and then get redirected or display somewhere. That was the idea. I guess since no one commented, its not possible. 

Ron Chatterjee

unread,
Mar 5, 2015, 12:41:36 PM3/5/15
to web...@googlegroups.com

In other words,



On Thursday, March 5, 2015 at 12:26:32 PM UTC-5, Ron Chatterjee wrote:
I like the way the search field shows up using smartgrid in web2py. But I dont want the table to b listed below because I want to customize the table display. Does anyone one if there way to display just the search box using smartgrid without displaying the table underneath.I know there is a way to create a search box using "like". But really like the search box from form factory  

Ron Chatterjee

unread,
Mar 6, 2015, 10:32:22 AM3/6/15
to web...@googlegroups.com
18 views and not one single comment. It seems I may have asked the most complicated question, or its not even possible. Would have been nice though. Most sites have a search bar on the top to search for the content. Rather than reinventing the wheel (the purpose of a framework), I could quick and dirty way, include the search bar on the top of my front page using the grid and then redirect the results to another page and later on "beatify" or make it look pretty or customize. But for the most part, I could have the site done. And that search bar do work folks. I have put in content in it and it was able to satisfy my query. May be all the mighty people on this community who controls, will consider this to be a feature request!!!?

Leonel Câmara

unread,
Mar 6, 2015, 10:57:00 AM3/6/15
to web...@googlegroups.com
It's not that this isn't possible, it's just that it doesn't make much sense to use smartgrid if all you want is a searchbox.

Anyway... Here's how you can do it. I don't recommend people use this.

controller:

def test():
    grid
= SQLFORM.smartgrid(db.mytable)
   
return locals()


view:

{{extend 'layout.html'}}
{{=grid.element('.web2py_console form')}}


<ul>
{{for row in grid.rows:}}
   
<li>{{=row.title}}</li>
{{pass}}
</ul>



This assumes, for the sake of example, that the resulting rows have a title field.

Ron Chatterjee

unread,
Mar 6, 2015, 11:13:24 AM3/6/15
to web...@googlegroups.com

Thank u for responding.  U misunderstood. I m trying to have a search bar on the top of the page without having the table populated below. The idea was to link my tables to the search n when some one puts a query it redirect s them to the table based on the query. Lets say I want a complete blank index.html with nothing but a white search box. Like what u see using the grid. But no table underneath to display. Then if someone search a query, it redirect them to a page with the results.  Most pages I see shows up that way. The code u send me, I did that. But its same as showing smartgrid on the front page. Thats not what I was after.

--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/xTCJzJrRuoo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Leonel Câmara

unread,
Mar 6, 2015, 11:27:01 AM3/6/15
to web...@googlegroups.com
Well you can use LOAD to put the form there and then have the controller redirect if it has results.

But really it's much simpler to just make your own search.

Ron Chatterjee

unread,
Mar 6, 2015, 11:37:15 AM3/6/15
to web...@googlegroups.com

Can u send me a.link or point me to the chapter in the book? U can add. These mins to 37 that u mentioned.  Its cool.

On Mar 6, 2015 11:27 AM, "Leonel Câmara" <leonel...@gmail.com> wrote:
Well you can use LOAD to put the form there and then have the controller redirect if it has results.

But really it's much simpler to just make your own search.

--

Ron Chatterjee

unread,
Mar 6, 2015, 11:48:59 AM3/6/15
to web...@googlegroups.com

I mean python, web2py context. Without using jscript. Anyone have an example of creating a simple search box that are linked to ur datanase table?

--

Ron Chatterjee

unread,
Mar 6, 2015, 12:19:24 PM3/6/15
to web...@googlegroups.com
https://gist.github.com/mdipierro/5479683

May be? Did anyone tried Whoosh?
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.

Massimo Di Pierro

unread,
Mar 6, 2015, 1:06:21 PM3/6/15
to web...@googlegroups.com
I agree with Leonel,

is is better to make your own search. The all point of the grid is pagination of results. If that is not what you need, make your own search using this:

from pydal.helpers.methods import smart_query

list_of_searchable_fields = [db.table.field1, db.table.field2, ...]

query = smart_query(list_of_searchable_fields, search_text)

rows = db(query).select()


This supports the same search syntax as the grid.

Ron Chatterjee

unread,
Mar 6, 2015, 1:36:35 PM3/6/15
to web...@googlegroups.com

I had to download paydal. It seems working. Except I need to difine search_text. N since thats an input, I believe i need to do form=SQLFORM.factory (Field ('search_text', label='peak inside', requires=IS_NOT_EMPTY ())) n then if form.process.accepted (): search_text = form.vars.search_name redirect(URL ('search results')). Right?

--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/xTCJzJrRuoo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Ron Chatterjee

unread,
Mar 6, 2015, 6:10:13 PM3/6/15
to web...@googlegroups.com

Massimo, whats the right syntax to pass the variable to smart_query? U mentioned list. But [db.table.field] gives u the dal object n the code given me a error on line 110 in methods.py . U have isinstance (fields, (list, tuple))). So I believe smart_query takes in list or tuple. But how do I create a list or tuple from dal? I asked cuz it gives me a run time error. If I do db ().select (db.table.field) that makes a set. What will make a list/tuple so isinstance will b satisfied?  Whats the right way to pass that variable into the routine. It cant b [db.table.field].

On Mar 6, 2015 1:06 PM, "Massimo Di Pierro" <massimo....@gmail.com> wrote:
--

Ron Chatterjee

unread,
Mar 6, 2015, 6:34:29 PM3/6/15
to web...@googlegroups.com

That code got bug in it. It cant b right.

On Mar 6, 2015 1:06 PM, "Massimo Di Pierro" <massimo....@gmail.com> wrote:
--

Ron Chatterjee

unread,
Mar 7, 2015, 3:56:58 PM3/7/15
to web...@googlegroups.com, Massimo DiPierro

Another way to do it is crud .search (db.table, query....)

On Mar 6, 2015 10:57 AM, "Leonel Câmara" <leonel...@gmail.com> wrote:
--
Reply all
Reply to author
Forward
0 new messages