search box send query on every keypress
search box send query on every keypress
kae
Posts: 2Questions: 0Answers: 0
I have a database with over 2 million entries in it, of cities and variants of their spellings.
when I type, say, "monaghan", datatables sends a search query for every key press.
I'm a fast typist, and am finished typing the word well before the first result comes back.
there is a race condition here, though, as a search for "mon" will sometimes be finished well after before a search for "monaghan", so when those results come back, the table will be updated with the results of a search for "mon" instead of "monaghan".
a solution here is to delay the search query until a reasonable time (say, 300ms) has gone after the last keypress.
when I type, say, "monaghan", datatables sends a search query for every key press.
I'm a fast typist, and am finished typing the word well before the first result comes back.
there is a race condition here, though, as a search for "mon" will sometimes be finished well after before a search for "monaghan", so when those results come back, the table will be updated with the results of a search for "mon" instead of "monaghan".
a solution here is to delay the search query until a reasonable time (say, 300ms) has gone after the last keypress.
This discussion has been closed.
Replies
2 million records - good going :-)
Fully agree - you don't want to DDOS your own server with DataTables(!!!) and that's what the fnSetFilteringDelay plug-in is for: http://datatables.net/plug-ins#api_fnSetFilteringDelay . It does exactly what you describe (well almost - the default is 250mS rather than 300mS - but that is customisable ;-) ).
Regards,
Allan