How to trigger search builder query results on custom button click
How to trigger search builder query results on custom button click
To improve the performance of filtering of my table with search builder extension on the client-side, I am trying to figure out how to trigger the search(filtering) from a custom button click and not automatically as and when the search criteria are added. I found that the documentation has the option to trigger the search on enter keypress but I would like to have the same functionality on a button click after building the search query.
Is there a way I can have a button click that triggers the search with search criteria, that then filters the table?
Answers
Yes, the
searchBuilder.rebuild()
method can be used to do this.What you might want to do is set up the search and then use
searchBuilder.getDetails()
to get the state object, rather than needing to construct it yourself. Then put that into your click event handler withsearchBuilder.rebuild()
.Allan
Hi Allan Thanks for the response.
Once the column and condition are selected, auto search is performed, and is there any way to restrict this behavior so that I can trigger searchBilder.rebuild() on the custom button click.
I'm afraid I don't understand. If you want the rebuild to happen only on a button click, then you'd assign a click event listener to the button that would perform that action.
Allan
Hi Allan,
My apologies if I am not clear. Within the search builder window, upon selecting the column and condition, a search is performed immediately on the table. Instead of displaying the results immediately, Within a custom button click event, I would like to get the details using searchBuilder.getDetails() and perform searchBuilder.rebuild(). For this, I don't want to show the search results immediately as the user builds the query. With huge data sets sometimes I see a performance impact and I would like to wait untill the user builds the query and click the custom button to perform search.
I see - thanks for the clarification. At the moment, no - what you are looking for is not possible. Sorry.
Allan
Hi Allan,
Thanks for this mind-blowingly excellent tool!
Just checking this has not been added more recently? Or if there are any tips for my situation:
Partial Fix
I have a partial/quick fix in place with
search: { return: true },
combined with a click handler for my custom search btn that simply callsthis.$refs.table.dt.draw();
However, seem to be other times e.g.
that the draw() is kicked off automatically.
Things I've tried:
None of these seem to work... so checking in-case you have any ideas/suggestions... or happen to have already sorted this somehow that I'm not seeing?
Proposal
Would be amazing to have a bool to inhibit all the automatic draws.
Something like
searchBuilder: { autoSearch: false }
Oh just realised the filterChanged method is not what's calling draw(); at all... sorry ! silly me. So looks like I'd have to mess with something like 14 occurrences in the source... any suggestions/tips would be hugely appreciated.
Yeah - any
draw()
call will trigger the filtering, and there are a whole bunch of them scattered through the code unfortunately. That is something that really needs to be tided up.Unfortunately, this isn't something that I've yet looked into implementing. The idea that each action would kick off a search was kind of engrained into it as we simply didn't think about the need for a button to trigger the search - which I can see now would be useful!
Perhaps a function that wraps the
draw()
call would be best -maybeDraw()
and if the option to wait for the button press is set, then it just wouldn't calldraw()
on the host table. The button would calldraw()
.The one complication with that is when the user interacts with the table (global search, order, paging) the filters will be applied, since they are already on the table, just not activated. That might be a bit of a confusing interaction.
Allan