Dropdown List connected wiath a database

Hy, I´m new with wixcode and I have a question:
I need to connect a dropdown list with a database so the user could select an item from the dropdown list and it wold be used as a filter to select data.


Thank You
(sorry about my English but I think you´ll understand)

Check out this video:

and this article:

Thank you, Ofer

I´ve tryed bu it doesn´t work. I think it´s because I´m using related fields in the Client Table.
I have an table “EstadosCidades” that contains the name of the cities and the state where it belongs.
I, also, have a table “Profissao” that contais the profession of the client
In the client table there are related fields to the “EstadosCiddes” and “Profissão” tables, like this:


The dropdown list are like this:


When I first enter the page it´s showing all the clientes and it´s correct.


But when I try to choose an value to the city and the profession, the filter doesn´t work.


If I use tables instead dropdown it work’s!


Thank you!

Can you show how you defined the dropdown selection to affect the table filter?

I didn´t use any code. I´ve tried to udse the one yopu sen me bau it didnt work

How does the table get filtered? If via the filter settings in the “Manage Dataset” panel, can you show that?

Also, if possible, it might be helpful to post a link to your site where we can see the issue

Yes, via filter settings in the “Manage Dataset”.

This is the link to the site:
https://www.pepc.com.br/

The options are in the “More” Menu

Thank You

Hi,

I see you’ve tried to apply the filter with code, but it looks like you’re querying the wrong collection - you should query the Clients collection, and filter it by the value of the dropdown.
(It looks like you are querying the EstadosCidades collection currently).

Also, I was asking about the filters defined via the “Manage Dataset” panel, but the screenshots you posted are of the “Connect Table” panel.
The “Manage Dataset” panel is available when you select the Dataset itself in the editor.


Click this, and then “Manage Dataset” and you will see the option to add Filters via the UI.

Hope this helps

Hi Ofer

I´ve tried but it doesn´t work.
I have deleted e all the page and reconstructed it from the beginning and now, without any filter, even the dataset clientes doesn´t work!

Hi Stephane,

It seems you have encountered a bug in the product.

See this forum thread for a quick workaround: https://www.wix.com/code/home/forum/questions-answers/reasonable-new-to-relating-databases

Hi Ofer,
Do you have any idea when it will be fixed?
Thank you

Hi Ofer,
I´m still having problem with this.
Using tables and filters within dataset, sometimes it works and sometimes it doesn’t

I´d like to use a dropdownlist to choose the profession and the city, but it´s not working


I used this page with the following code:]

Can you help me?

Thank you

S. Vannier

The fields “cidade” and “profissao” in the “clientes” table are related to the “Profissao” and “EstadosCidades” tables.

Hi Ofer,
Is there anybody who can help me with this?
Thank You

Hi Stephane,

From looking at the code I see one possible problem - the code does not account for filtering by both attributes together - if selections are made in both dropdowns, the query you build should have 2 filters.

It is not entirely clear what you mean by “sometimes it works and sometimes not” - do you get errors in the console (Check the browser developer console)? Do you get the wrong result?

I tried accessing your page, but for me it fails to load properly due to lack of permissions on the EstadosCidades collection - you probably need to add “read” permissions to anonymous users on that collection. I can have another look once you fix this.

Good luck!

Hi Ofer, I´ve fixed the permission to the EstadosCidades collection. I think that´s the problem I told you. Now it seems to be ok.
What I´m trying to do is to filter the Clientes colletcion by Profissao and EstadosCidades. It works nown using the Clientes-2 page but I´d like to use the Clientes-1 interface, using the dropdwn list and not tables.
Thank You

OK, now I can suggest the following approach:

Connect the table to the Clientes dataset, and do not define any design-time filters on the dataset.

Add the following function to the page’s code:

function updateFilters() {
 const profissao = $w('#dropdown2').value
 const cidade = $w('#dropdown3').value
 let filter = wixData.filter();
 if (profissao) {
     filter = filter.eq('profissao', profissao)
 }
 if (cidade) {
     filter = filter.eq('cidade', cidade)
 }
 $w('#dataset1').setFilter(filter)
}


In each of the 2 dropdown’s onChange handlers call the “updateFilters”.
So on every change of any one of the dropdowns, you will build a filter that accounts for both parameters.

Setting the filter on the dataset makes it refresh its data according to those filters.
Since the table is connected to this dataset, it will automatically refresh to display the current data in the dataset which should now be filtered according to the selections in both of the dropdowns.

Good luck :slight_smile: