Data Filters in Apps - dropdown/date filter in an App

  • Goal: I want to create an App with some visualizations and use some filters (Date, dropdown) on the top of my page to filter the dashboard using those filters.
  • Steps:
  1. I have created an App and added the filter components in it.
  2. Now I am unable to figure out how to connect these filters to the data and use them to filter the data on the App.

If I select any value on this dropdown filter, it is not filtering the values on the page. How can I achieve this?

Can anyone please help me out here. Much appreciated!
Thanks

Hello @sidharth1995,

You can add some of these conditions to your queries in order to filter the results based on your selected options:
image

First one is for text inputs, second one is for multiselects and third one is for normal selects. Don't forget to change "title" and the components names to match your app.

Let me know if this helps!

Hi @GuilhermeSilva , Thanks for the advice, I have tried the below code but still it is not working.

Can you please advice where I might be going wrong?

Thanks!

Hi,

You should be filtering query4 using that multiselect code, not query6.
query6 should be a simple query with a list of statuses to populate the multiselect, for instance:

select status from data

Hi @GuilhermeSilva ,

I am trying, but the query is not working. Is there something that is missing in the syntax?

Please have a look and advice.

Much Appreciated!
Thanks

Hi @sidharth1995,

The query should be:

SELECT * FROM SUPPLY_CHAIN.SUPPLY_CHAIN_DATA WHERE ({{multiselect1.value == '' }} OR ORDER_STATUS = ANY({{multiselect1.value}}))

Hi @GuilhermeSilva , Thanks for replying!

I ran this query but it is not returning any data. See below:

The source of your multiselect shouldn't be the same query, it should be a list of statuses, either from database or manually input. Maybe for now, switch the mode to manual and insert the status manually.
Can you show what the error is on the query?

Hi @GuilhermeSilva , I have given different query as data source to multiselect which only shows status column from the table.
Now I am running the query and it is showing below error:

Please advise!

Thanks

Hi @sidharth1995,

@GuilhermeSilva is on the right track, but there're a couple of things going on:

  1. ( {{ multiselect.value == '' }} ) evaluates to a boolean.
  2. With no selection the value of multiselect.value is [].

Our query currently looks like:

SELECT * FROM table_name WHERE true/false OR order_status = ANY(['selection1', 'selection2'])

Here is one implementation for your use case:

One query to get all results (in case of no selection)
Screenshot 2024-10-18 at 10.48.54 AM

One query to get filtered results
Screenshot 2024-10-18 at 10.49.18 AM

A dynamic 'Data source' for the table component
{{ multiselect1.value.length > 0 ? getFilteredUsers.data : getAllUsers.data }}

In action:

No selection
Screenshot 2024-10-18 at 10.51.07 AM

Single selection
Screenshot 2024-10-18 at 10.50.36 AM

Multiple selection

Hi @Paulo , thanks for looking into this!

I have tried your approach and created 2 separate queries. Still facing error in the filtered query. see below:

Can you please advise.

Thanks!

From our SQL Cheatsheet:

Try this syntax instead.

1 Like

Hi @Paulo , I am using this. but it is not returning any data.

Can we please connect over zoom call or something? I am doing a POC on Retool to check if it will be a good fit for our company or not. I have few doubts in REST API, Workflows and data filters.

Let me know if its possible or if you can connect me with some technical person.

Thanks!

That was an example. Replace [123,224] with your array (multiselect1.value) and make sure you haven't disabled prepared statements on your Resource's configuration:

For live support, you can join us during Office Hours next Tuesday at 11am PST.

Sure I will join next week Tuesday. Thanks @Paulo .

1 Like

Hello @sidharth1995,

Snowflake has a different structure and syntax, can you try this?
If it doesn't work, it's probably best to follow Paulo's advice and join office hours next Tuesday.

SELECT * FROM SUPPLY_CHAIN.SUPPLY_CHAIN_DATA
WHERE ({{multiselect1.value.length == 0}} 
OR ARRAY_CONTAINS(ORDER_STATUS::variant, SPLIT({{multiselect1.value.join("---")}},'---')))
1 Like

@TRF got this working a few days ago:

2 Likes

Hi @sidharth1995, did @TRF's implementation solve your issue?

1 Like