Hi,
I am using the Query Builder and wonder if it is possible to be able to load an existing set of query criteria back into a QueryBuilder component next time the app is loaded?
I can't seem to see a way to so it, but apologies if i'm just being daft.
Thanks
Martin
Hey @mkeywood! I believe you should be able to do this using the value
property in your inspector:
If you have your query format saved somewhere, like lets say in a Transformer, you can reference it like so:
The value
property takes a JSON object, so you'd probably want to export that format from an already filled in query builder and put it in a Transformer or temp state somewhere.
Hope this helps!
Thanks @justin for the response.
I tried that, but maybe I am getting something wrong (probably ).
I have a state called allQueries which is an array, with each element being an object with two keys - name and value.
name is being set to a text box for a free text query name, and value set to the value field as you say:
allQueries.setValue(allQueries.value.concat([{ "name": queryName.value, "value": querybuilder1.value }]));
So if I look at the first query in that list (allQueries.value[0].value
), it show's me:
{"id":"g-a887aa18-e773-448e-8288-5a893d097176","rules":[{"id":"r-e1b68a10-6ee8-4b85-b064-e98500ceb4aa","field":"tri.T_Therapeutic_area","value":["","Dermatology"],"operator":"in"}],"combinator":"and"}
But when I try and set it back with the following, it doesn't seem to do anything
querybuilder1.value = allQueries.value[0].value
Can I set that value programmatically?
@mkeywood the .value
property is read only. You'll need to set the value via the UI that I mentioned above.
Ah OK, thanks. That's a real limiting factor as I need a way of recalling 'saved' queries to allow simple futures tweaks / edits.
That's a shame. I'll see if i can use something other than QueryBuilder.
Thanks again for your quick responses and help
For sure! I think you can just do all of that logic in a Transformer (which query we want to set the value as, when, etc.) and then just reference the value of that transformer like above. But I totally understand that it would be easier to programatically set