it's possible to use Autocomplete widget in SQLFORM.grid ?

68 views
Skip to first unread message

Sandeep Patel

unread,
May 21, 2018, 8:37:40 AM5/21/18
to web...@googlegroups.com
Hello,
Can anyone, let me know how to work Autocomplete widget with SQLFROM.grid in the search filed. I have used Autocomplete widget in SQLFROM that's work fine but in the grid, nothing in happen.


Please give me some direction how to do that.


Thank's
Sandeep

Message has been deleted

isi_jca

unread,
May 24, 2018, 4:49:27 PM5/24/18
to web2py-users

Sandeep Patel

unread,
May 25, 2018, 1:51:37 AM5/25/18
to web...@googlegroups.com

@isi_jca
I have read some old threads, it seems to me that the web2py inbuild widget works with FORMS and not with the grid.
But that's doesn't mean we can not do that. I have done so with the help of jQury.

See my sample Code

# Controller.py
def myfuc():
grid = SQLFROM.grid(.....)

grid.insert(1,DIV(_style="position: absolute;background-color: #ffffff;border: 1px solid #1364a5",_id="suggestions",_class="suggestions"))
return  locals()
# veiw/myfuc.html
{{ 'include layout.html'}}
{{=grid}}
<script>
jQuery( document ).ready(function( $ ){
jQuery("#w2p_keywords").keyup(function(){
ajax('{{=URL('default', 'selector')}}', ['keywords'], 'suggestions');
jQuery('#suggestions').click(function(){jQuery('#suggestions').hide()
});
});
});

</script>

Now, this script worked for me. Just want to update you and others.
Thanks for your advice. Greatly  appreciated



--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sandeep Patel

unread,
May 25, 2018, 2:01:38 AM5/25/18
to web...@googlegroups.com
Sorry i didn't mention in my previous post , 

this is also be in controller.py
def selector():
    if not request.vars.keywords:
        return ''
    pattern = request.vars.keywords + '%'
    selected = list(set([row.customer_name for row in db((db.inward_entries.customer_name.like(pattern,case_sensitive=False))(db.inward_entries.created_by==auth.user.id)).select(limitby=(0, 10))]))
    return ''.join([DIV(k,
                 _onclick="jQuery('#w2p_keywords').val('%s')" % k,
                 _onmouseover="this.style.backgroundColor='yellow'",
                 _onmouseout="this.style.backgroundColor='white'"
                 ).xml() for k in selected])

Thanks
Sandeep
Reply all
Reply to author
Forward
0 new messages