Is it possible to set a table's filters and sort order with URL parameters?

We have a table that's used by several different groups of people. Each group has different filter preferences and would like their own custom bookmark.

I've looked at how Deeplinking works, which seems perfect for this situation, however there does not appear to be a way to set the table's filter or sort attributes from the URL:

Does anyone have a workaround or some additional insight here?

Hey @model_2! You can access URL params globally in your Retool app as {{ urlparams.param }} - so you can set table filters / queries based on that!

@model_2 did you ever figure out how to bind the URL parameters to a table’s filters automatically? I think I might be able to do it individually for each column in the query, but I’m wondering if you found an easy way to set it up.

@justin Is there an obvious way to add all of the parameters to the table to pre-set the filters? I’m hoping there’s some easy way to bind them, rather than build a whole bunch of custom logic. Am I overthinking this?

@danwolch I don’t think you’re overthinking it :slight_smile: we don’t have any “native” functionality for this, but it’s as simple as just parsing whatever is in the URL via {{ urlparams.param }}. So I guess it depends on where you’re applying the filters - if it’s in your query, you can just reference the params directly.

@justin Where would you put that? When can I set the filter attributes on a table?

I don't want to pass in the values to the query that populates the table, I want all of the data to come back so they can clear the filters if they want and see all of the data.

This is what I'm doing with the URL parameters, :

What gets stored in the URL:
tableFilter = {{JSON.stringify(users_list.filters)}}

I connect these properties to values in the URL:
users_list_filters.value = {{JSON.parse(urlparams.hash.tablefilter)}}

After the last query to populate our data (I'm merging data from multiple queries), I specify a success query that attempts to set the filters on the table:

image

This doesn't seem to work for the users_list table and its filters. Should this work?

Ah nope, the .filters property is read only. Currently there’s no way to dynamically filter tables in the table component itself - general best practice here is to do that in your query. You could also use a JS Transformer to apply those filters via JS (you’d need to build that logic yourself) and then display the transformer’s results in the table (if you want to avoid re-querying your DB every time your filters change).

Thanks, Justin.

I just posted a feature request for this here: Make filters on tables read/write. If I can persist the filters in the URL, why can’t I use the values in the URL to update a table on page load? Feels like a missing feature.

The whole point of a filter is that you don’t have to do filtering in the original query, and you can always clear the filters to see all of the results. Right?

@danwolch the main use case for table filters is ad hoc filtering and searching, not necessarily reusable static filters - because if you’re doing that, why not put it in the query logic? But I can definitely see the use case for programmable filters, and I think it makes sense for us to work on when we can!

1 Like

Hey Justin!

I find that being able to create reusable filters in the table itself would be a great feature as we have some users who are technologically equipped to edit a SQL query, but we will be using Retool with some users who do not know anything about SQL. Moving the filtering into the query itself removes the ability of non-technical people to be able to edit the view if they want to.

1 Like