Click here to Skip to main content
15,886,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am having an issue with jquery autocomplete where the requirement is to pull a list of thousands records from database and to render on autocomplete dropdown list.

I have bind data load on keydown event, and when i type any character with a time interval of 1 sec or less than it render the result for every character respectively.
Example i press 'a' than 'j' than 'a' and than 'x' than it will render result initially matching 'a' than reload with result for 'aj' than for 'aja' than last for 'ajax'.

I want the behavior like if i press another character than it should cancel older request and render only new result. And for the same i tried with cancel ajax call using .abort() method, but still it is rendering old result first than refresh result with new call. Even i entered second another character before rendering old result.

Please help me to solve this issue.
Posted

1 solution

I wonder what is the real requirement: 1) to provide a choice in a UI from thousands of records, or 2) use exactly autocomplete to assist such choice.

If the "requirement" you faced is #1, this is just a bad "requirement". If it is #2, it is completely idiotic "requirement". The autocomplete mechanism, by design and just be common sense, is supposed to be fairly fast. Even if the user got it quickly, the human operator is hardly capable of critically considering the choice between some autocomplete-based options on the fly, if the total number of possibilities is some thousands.

In both cases, the only reasonable solution is not doing it. And you are trying to substitute the real solution with a programming crutch — aborting the autocomplete. It will lead you nowhere. Roughly speaking, in real use, nearly 100% of autocomplete operations will be aborted.

The right solution is to redesign the UI. There are many possibilities. For example, you can perform additional query on the result set, if thousands of record is the result set. If this is all the data, you just need some query. You can also use some list view with paging, with different sorting criteria chosen by the user. It all also depends on the semantic of the data.

And please don't repeat the common mistake, don't tell me that this is the requirement you got to meet. Then talk to people who gave your this "requirement". If they insist, let them talk to me.

—SA
 
Share this answer
 
Comments
Wonde Tadesse 7-May-15 7:15am    
5+. Welcome to the millions SA!
Sergey Alexandrovich Kryukov 7-May-15 9:07am    
Thank you, Wonde.
—SA
Chandrakant Kumawat 7-May-15 9:22am    
Thanks Sergey !
Sergey Alexandrovich Kryukov 7-May-15 9:24am    
You are very welcome.
Good luck, call again.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900