Changing Table Data Source Deletes all Default Filters - preserve default filters instead

Steps to Reproduce:

  1. Create a new table.
  2. Set its data Source
  3. Add one or more Default Filters.
  4. Change Data Source to a different query

Your Default Filters will be cleared.

@bradlymathews thank you for surfacing this and thanks for your patience! I checked with our eng team internally, and it sounds like these are intentionally cleared because when the data source changes, we could have a default filter referencing a column that no longer exists. For example a filter could be referencing a column "name" in one data source, but the second data source you switched to doesn't have "name", it only has other columns like "date" or "title" etc. So the filters would no longer make sense and would have to be manually changed anyways :thinking:

A possible suggestion to try would be to persist filters by storing the filters and calling setFilters on the table after data refresh. Would that maybe work well enough for what you need?

Hi @kbn ,you mistake @bradlymathews , he want to clear Default filters intentionally(automaticlly) but fact is not so.

I see the logic in resetting the filters. However, if I am simply changing to a query that has the same or very similar columns in the result (I may do that a bit in early development or when making a major update) I think it may be better to follow the example of the table's Columns list and put a warning icon
instead of clearing.

I was curious about whether .setFilter would link to components reactively. This does not seem to work:

  filters: [
    {columnId: 'product_name', operator: 'includes', value:txtSearchProduct.value}

These are the filters I am applying:


I used to download the entire table and the use JSON SQL queries for the filtering, and this is the first app I am using the New Table's Filters for that instead. I like it better since the table's logic is less spread around.

@AnsonHwang , Kayla's got it right. :grinning:

1 Like

@bradlymathews thank you for elaborating on how you'd want to use this! I was chatting with @mckenna who's one of the engineers working on Table features -- we do think it would be reasonable to preserve the default filters if the writeable column key exists in the new set of columns, and just discard the others. It seems like that would solve your use case?

We created an internal feature request ticket for this, and I'll move this over to the Feature Requests section of the forum to continue tracking interest. Semi-relatedly, we also created an internal ticket for a related request about clearing default filters that came up recently:

In terms of using .setFilter I see what you mean that that's not going to work here, I didn’t count on the filters themselves having dynamic values/referencing other Retool objects

Glad you're finding that using the New Table's Filters is generally better since the table's logic is more centralized and less spread around :raised_hands:

@bradlymathews to follow up on this -- I've merged a change which will retain all default filters connected to columns which persist following a data source change. This means that columns that reference source keys that have unchanged or custom columns will not have their default filters cleared.

The fix will be available in next week's cloud release!

1 Like

@bradlymathews does the updated functionality that @mckenna shipped work well for you? Let us know if that resolves your original request here!

I have not had a chance to test this out yet.