Ruby on Rails : a dynamic pick list for 1000+ candidates

40 views
Skip to first unread message

David Ng

unread,
Jun 26, 2015, 1:19:02 AM6/26/15
to rubyonra...@googlegroups.com

I am working on a Ruby on Rails project where I need to associated 2 tables. A pick-list "f.select" is good for a short list (less than 20). If I have a very long list, let say picking a stock out of thousand stocks in stock market for an trading order, what should I do? 

I saw some dynamic search pick list, I mean the pick list is updated whenever I type one character. DO i have to do it in Javascript ?

Thanks in advance.

David



Ganesh Ranganathan

unread,
Jun 26, 2015, 3:43:56 AM6/26/15
to rubyonra...@googlegroups.com

On Fri, Jun 26, 2015 at 7:52 AM, David Ng <david...@gmail.com> wrote:
I saw some dynamic search pick list, I mean the pick list is updated whenever I type one character. DO i have to do it in Javascript ?

​This can be done with jquery. On the change event of the textbox , make an ajax call to a action which takes in the typed text and returns a json array of objects to be populated in the list. In the success handler of the ajax call, remove all existing elements in the list and add the new ones returned by the action.

If you use angular, this can be done more elegantly than in JQuery.​

Colin Law

unread,
Jun 26, 2015, 3:51:20 AM6/26/15
to rubyonra...@googlegroups.com
On 26 June 2015 at 08:43, Ganesh Ranganathan
<ganesh.ran...@gmail.com> wrote:
>
> On Fri, Jun 26, 2015 at 7:52 AM, David Ng <david...@gmail.com> wrote:
>>
>> I saw some dynamic search pick list, I mean the pick list is updated
>> whenever I type one character. DO i have to do it in Javascript ?
>
>
> This can be done with jquery. On the change event of the textbox , make an
> ajax call to a action which takes in the typed text and returns a json array
> of objects to be populated in the list. In the success handler of the ajax
> call, remove all existing elements in the list and add the new ones returned
> by the action.

That way will involve a server request for every character typed,
since that could easily be several seconds and maybe a lot more this
will introduce intolerable delays for the user.

For acceptable performance send the complete list to the browser and
manage the selection in javascript.

Colin

Ganesh Ranganathan

unread,
Jun 26, 2015, 10:57:58 AM6/26/15
to rubyonra...@googlegroups.com

On Fri, Jun 26, 2015 at 1:20 PM, Colin Law <cla...@gmail.com> wrote:

That way will involve a server request for every character typed,
since that could easily be several seconds and maybe a lot more this
will introduce intolerable delays for the user.


​I implemented this with a three character minimum input and the delay was minimum - Barely a fraction of a second. ​ The server based approach works very well with an indexed column on the DB for even 10K records.

Thanks,
Ganesh

Colin Law

unread,
Jun 26, 2015, 11:27:58 AM6/26/15
to rubyonra...@googlegroups.com
On 26 June 2015 at 15:57, Ganesh Ranganathan
Was that across the internet? If so you must have a good internet
connection and a good server. Try it on a weak mobile connection with
a slow server the other side of the world.

Colin
Reply all
Reply to author
Forward
0 new messages