Saving multiple SearchBuilder queries

Saving multiple SearchBuilder queries

craig91craig91 Posts: 9Questions: 3Answers: 0

Would it be possible to save multiple SearchBuilder queries? I am thinking of 1 or 2 possibilities that would be very nice to have.

  1. Provide pre-configured SearchBuilder queries using a button or dropdown. So I can provide some off the shelf filtering options that would be relevant for the dataset.

  2. Allow a user on the frontend to create their own SearchBuilder queries, and save it in cache. Ideally this would not just be a single state save of their last SearchBuilder query, instead it would allow the user to save multiple queries and have them appear as options in some kind of dropdown/buttons.

Perhaps 1 is easier, maybe I can add custom buttons and programmatically update SearchBuilder each time one is clicked. Or maybe that is better accomplished using a custom search function for each button click. For number 2 it might be more difficult, but it would be pretty neat.

Let me know your thoughts, thank you for this awesome extension.

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,177Questions: 1Answers: 2,590

    Yep, both are possible. For 1, you can load a search using the API, see example here. And for 2, you can use stateSave to save the search info for that particular user, see example here.

    Colin

  • craig91craig91 Posts: 9Questions: 3Answers: 0

    Thanks Colin.

    I think the state save that you linked to was what I mentioned, and it would only allow to save the last query per user if I am not mistaken. For the second I am specifically looking to allow saving multiple queries per user, so user 1 can create for example 5 different queries, and save them so they appear as available options next time the user comes back to the page and they can be easily toggle through a dropdown/button rather than the user needing to input each query again. I would think of them as SearchBuilder Shortcuts.

  • colincolin Posts: 15,177Questions: 1Answers: 2,590
    Answer ✓

    That's not something we provide, I'm afraid, so you'll need to implement that yourself and use the API to load any saved queries. You can store additional information with the stateSave data, so you can make a list of previous searches stored alongside the standard state information,

    Colin

  • craig91craig91 Posts: 9Questions: 3Answers: 0

    Thanks Colin, I will give it a shot.

  • sandysandy Posts: 913Questions: 0Answers: 236
    Answer ✓

    Hi @craig91 ,

    Just to expand on colins answer, you could use the searchBuilder.getDetails() method to get the structure and then pass the result of that into the searchBuilder.rebuild() method. You could store as many results of the searchBuilder.getDetails() method as you like and pass in whichever ones you choose, but that is up to you for now I am afraid. This may be something that we look at in the future, but I can't say when that will be.

    Hope this helps,
    Sandy

  • craig91craig91 Posts: 9Questions: 3Answers: 0

    Thanks for the added info Sandy. It would be cool to see it built in to DT, however I will see about trying to implement myself in the meantime. :)

Sign In or Register to comment.