How to trigger search builder query results on custom button click

How to trigger search builder query results on custom button click

PRASADRAJACSEPRASADRAJACSE Posts: 4Questions: 2Answers: 0

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

  • allanallan Posts: 61,438Questions: 1Answers: 10,049 Site admin

    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 with searchBuilder.rebuild().

    Allan

  • PRASADRAJACSEPRASADRAJACSE Posts: 4Questions: 2Answers: 0

    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.

  • allanallan Posts: 61,438Questions: 1Answers: 10,049 Site admin

    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

  • PRASADRAJACSEPRASADRAJACSE Posts: 4Questions: 2Answers: 0

    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.

  • allanallan Posts: 61,438Questions: 1Answers: 10,049 Site admin

    I see - thanks for the clarification. At the moment, no - what you are looking for is not possible. Sorry.

    Allan

  • MemeDeveloperMemeDeveloper Posts: 5Questions: 0Answers: 0

    Hi Allan,

    Thanks for this mind-blowingly excellent tool! <3 <3

    Just checking this has not been added more recently? Or if there are any tips for my situation:

    • I have many millions of rows on the server
    • Am using (the excellent - thank you) .Net Editor library for server side implementation
    • Want to inhibit all the searchBuilder automatic calls which kick off a request to server (to .draw() I guess), and use a custom btn instead (when the user has finished setting up their query)

    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 calls this.$refs.table.dt.draw();

    However, seem to be other times e.g.

    • Remove a condition
    • Clear All

    that the draw() is kicked off automatically.

    Things I've tried:

    • modifying the source code myself (to no avail it seems due to my vite+vue setup my changes never come down the wire)
    • handing a custom filterChanged to the searchBuilder options
    • overriding the _filterChanged function (naughty I know) and returning false.

    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 }

  • MemeDeveloperMemeDeveloper Posts: 5Questions: 0Answers: 0
    edited September 2023

    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.

  • allanallan Posts: 61,438Questions: 1Answers: 10,049 Site admin

    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 call draw() on the host table. The button would call draw().

    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

Sign In or Register to comment.