I've a table with many columns, including "positioId' and "trader". My goal is that when a row is clicked, I want to update both query params in the URL with the correct values from the table. I've tried many things including running a query on click, I can also verify that the correct value is printed (using console.log) but it's not updating the query params. I've tried, among the rest:
urlparams.hash.detPosId = selectedPositionId.value
Hello @Roei_Natan, Welcome to the Retool Community!
You can update the query parameters in the URL using utils.setUrlParams()
.
Try this approach:
utils.setUrlParams({ detPosId: selectedRow.positionId, trader: selectedRow.trader });
Hi @Roei_Natan and welcome to the forum!
So, if I'm understanding this correctly you have an API query with a couple of parameters. This query needs to run when you click on a table row and you want to send the values in your positionId and trader columns to the parameters to run the query again and get the results, right?
If that's the case, I think there are two ways of approaching this:
- The simple, but not so proper way, is to refer to the selectedRow in your table directly from your API parameters, e.g.
table1.selectedRow.positionId
. If you set your query's behavior to run on "Automatic" then every time the variable above changes it will run. - The best way of appraoching this is using
additionalScope
which will then allow you to re-use your api query from other parts of the application. You will basically add to variable to your parameters, e.g. {{ positionId }} and {{ trader }} and you will create an event handler on click to trigger the query and pass the additionalScopes (in this case, passingselectedRow.positionId
, etc. Here's a link to a helpful post on how to use additional scope.
If you need further help, do share some screenshots of your setup.
Cheers and good luck!
@WidleStudioLLP I keep getting:
▶
Error:utils.setUrlParams is not a function
There isn't a utils function called that afaik.
I don't think this is the best idea but you can set URL params at the page settings level. This is more useful for passing data between apps, though. I don't think it'd auto-trigger the query either. Not ideal.
Using additionalScope and passing the params to your query definitely sounds like the best approach.
I am getting an error when trying to set query parameters with utils.setUrlParameters()
. I would like use this in a conditional statement within a javascript query. Is this currently possible?
HI all! I just want to confirm that there currently isn't a utils
method for directly setting query parameters. We instead recommend an approach that is similar to what @dcartlidge shared above.
The most flexible option is to define an app variable and then configure the page to map the value of that variable to a URL parameter.
This way, you can set the value of the variable from anywhere in your app and have that change be immediately reflected in the URL.
Note that both single and multi-page applications support this pattern, although the UI is a little bit different between the two. Let me know if you have any questions!