Custom search fires search event twice
Custom search fires search event twice

Link to test case: https://jsfiddle.net/svarcm/vpL0rqas/
Description of problem: When a custom search is used, the "search" event is fired twice for every query change.
This discussion has been closed.
Answers
I realized the second fire is because of necessary draw(), but is it possible to have a custom search with only one firing of search event?
As you say, it's because the draw is showing the filter, so unfortunately it's unavoidable.
I suspect the only way around it would be to use a global variable and break up the
search()
anddraw()
- using the variable to tell your handler to ignore the one you don't care about. It's clunky, but I can't think of another way around it, I'm afraid,Colin
One option might be to use the
draw
event to create a single instance event handler using one(). You will need to use off() first. See this example:https://jsfiddle.net/5sukd0bp/1/
Note that any table draw, ie sorting, paging, etc, will fire the
search
event.Kevin
Thanks for the nice solution, but search is still performed twice on the background, see https://jsfiddle.net/svarcm/gxqpu829/. I would be enough with original search box, but I need to modify query (remove accents) before search and there is aparently no way to do that. When you have table with 20k rows, performance is just twice as bad.