Searching a database

Hi all :slight_smile:

I was wondering if anyone could help me. I am new to code (brand new) and am having a bit of trouble with my drop down menus. Although I’m new to code, I’m loving the possibilities that it opens up for website design and functionality on the Wix platform!

I’ve created a database for a recruitment agency with a list of available jobs and fields (job title, classification, sub-classification, location, etc.)

With help from this fantastic forum I’ve been able to create a working:-
- Search field which filters the job title
- Drop down menu for location
- Drop Down menu for job classification

Unfortunately, My drop down menu shows all the locations listed in the database so there are double ups (see right) and there is no logical structure. As you can see Christchurch appears 3 times… etc.

My question is: How do I create a drop down that shows custom location values (New Zealand’s major regions, and not all the location values in the database column), which then searches the location field of my database?

I also wondered how to link all the search menus, so that each search box filters the results in conjunction with one another? For example Someone could type in ‘Pricing Analyst’, then select ‘Christchurch’ and then ‘Banking and Finance’, and get search results ONLY showing jobs that match all three specific criteria. At the moment the search menus work separately.

I hope this all made sense? Any help would be hugely appreciated! Thanks :slight_smile:

Jono

Below is the code I’ve got so far:-

Hi,
I recommend checking out this video tutorial . Moreover, you can check this thread for filtering repeater and this thread for filtering table using multiple user inputs.

Good luck,
Tal.

Thanks Tal,

I will have a look at these and see if I can figure it out. Thanks for your response!

Cheers,

Jono

Thanks!

I am now trying to link all the search menus, so that each search box filters the results in conjunction with one another. I have referred to the links provided by Tal (above) although due to the fact that I’m just starting out with code, I’m having trouble understanding the examples and determining what code is relevant to me and what is not.

Essentially I want to create a job search that works together to refine and filter results from my table. I would like it to filter results such as the example below. Any help would be much appreciated! I’ve spent so much time on this so far!


I have named my elements as follows:-

Search bar = ‘#input1
Location drop down = ‘#location1
Classification drop down = ‘#classification
Table = ‘#table1
Dataset = ‘#dataset2
Database = ‘careers’

So far my search bar and drop downs work independently of one another. Can anyone show me where I am going wrong? Many thanks!!!

My code so far is :-

import wixData from ‘wix-data’;

$w.onReady(function () {
//TODO: import wixData from ‘wix-data’;
});

export function input1_keyPress_1() {
wixData.query(‘careers’)
.contains(‘title’, $w(‘#input1’).value)
.find()
.then(res => {
$w(‘#table1’).rows = res.items;
});
}

export function location1_change_1(event, $w) {
wixData.query(‘careers’)
.contains(‘location’, $w(‘#location1’).value)
.find()
.then(res => {
$w(‘#table1’).rows = res.items;
$w(‘#table1’).show();
});

}

export function input1_viewportEnter(event, $w) {
wixData.query(‘careers’)
.contains(‘location’, $w(‘#location1’).value)
.find()
.then(res => {
$w(‘#table1’).rows = res.items;
$w(‘#table1’).show();
});
}

export function classification_change() {
wixData.query(‘careers’)
.contains(‘category’, $w(‘#classification’).value)
.find()
.then(res => {
$w(‘#table1’).rows = res.items;
$w(‘#table1’).show();
});
}

Hi,
You wish to have multiple filtering, meaning that whenever a user changes the drop down, it filters the results accordingly. In your case, you have 2 drop downs and one user input. I recommend using the JS filter function. The example here explains it pretty well. It’s even the same scenario :slight_smile:

The first step mentioned there is in order to get all results from the collection.

The second step is to get all user inputs values and filter the data accordingly. The if statements are in order to check if they are not set to the default values (in your case “keywords (optional)”, “Location” and “Classification”).

The third step is basically the onChange of each of your user input fields (in your case the Search bar, Location drop down andClassification drop down).

I hope it’s clearer now.

Good luck,
Tal.

1 Like

Thanks again Tal,

Please excuse my ignorance with Wix code, I’m still very new!

What is the green value ’ ‘כל המשרות’ in the example?
and ‘כל התחומים’ values? Sorry, I translated and it says ‘all jobs’ although
I’m confused as to what that would be in my case?

Cheers,

Jono

These are the default parameters that the other user used. Instead of ‘כל המשרות’, you should insert your default values : " keywords (optional) ", " Location " and " Classification ".

Hi Tal,

Thanks for your response and for your patience.

I still cant get it to work, there are no error messages showing when I run the code although I’m still not getting any results and the table remains blank. I was wondering if you were able to help we figure out where I am going wrong?

Am I missing anything?

I have named my elements as follows:-

Search bar = ’ #input1
Location drop down = ’ #location1
Classification drop down = ’ #classification
Table = ’ #table1
Dataset = ’ #dataset2
Database = ‘careers’

This is my code so far:

let originalRows = ;

$w.onReady(function () {
$w(‘#dataset1’).onReady(() => {
originalRows = $w(‘#table1’).rows;
});
});

function filterTable() {
let newRows = originalRows;
const field = $w(‘#location1’).value;
const location = $w(‘#classification’).value;
if (location && location !== ‘location’) {
newRows = newRows.filter(item => item.positionLocation === location);
}
if (field && field !== ‘category’) {
newRows = newRows.filter(item => item.Field === field);
}

$w('#table1').rows = newRows; 

}

export function location1_change(event, $w) {
filterTable();
}

export function classification_change(event, $w) {
filterTable();
}

Hi,
Is anyone able to help me with the above code? Any help would be much appreciated! Thanks

1 Like

Can someone help me with this code I will pay you!

1 Like

I need help, willing to pay someone to fix this search code for me

Hey take a look on the site
If you still need help just ping me on Salman
https://www.salman2301.com/multiple-filter

This is the exact code you need with 4 drops

I have tried different method this is pretty easy and scalable
By using this same code i have done 10 - 15 different user elements

Hi Tal, Please help me too… Please have a look…