joeharrison714 / MVCGrid.Net

http://mvcgrid.net
MIT License
74 stars 55 forks source link

Global search with deferred AJAX call #25

Open smillerk2 opened 8 years ago

smillerk2 commented 8 years ago

When using the global search, it would be great if there was a deferred event on the input field that waits so many seconds before firing the Ajax call. This would allow users to type in lengthy search criteria (e.g. a surname) rather than having the Ajax call fire for each individual key press event.

Is there anything out of the box that does this already? I couldn't see anything in the documentation.

ademgashi commented 8 years ago

+1 Also if it would be possible to fire on enter press for example...

lsamples commented 6 years ago

I was able to hack this functionality with the following approach. On page load, I use JQuery to hide the existing global search box, and add another identical looking one in its place. With a listener on that input's keyup event, I can then add whatever logic I want to delay the search. When ready to do the actual search, set the value of the now hidden original search box, and call the keyup() event.

I wish there was a cleaner way to intercept this event. It is pretty wasteful to do an entire search for the letter 'a' most of the time. Seems like a min character limit would be an easy option to add to the global search.