Multiple Search Function Help??

Hi,

I have created a database, which I want to be searchable to my site members.

Currently, I can only find a way to allow for members to search one field of the database.

My question is, is there a code which would allow for multiple field searches to be displayed at once?

As an example - my Database is populated via a form, which contains data such as : First Name, Second Name, Job Title, Location and Salary…

I want my members to be able to carry out a search which would allow them to display people who match a certain variable criteria, such as:

Member searches for : ( Job title) + (Location) + (Salary) = Return of people from the database who match each of the specified fields which have been searched for…

So if a member searched for a user who was a (Lawyer) who lives in the ( United Kingdom) and currently earns a salary of ( £30,000-£40,000) - the database would show a list of people who match all of those certain fields?

Any help would be great! - I hope the above all makes sense!

Hi Ashley,

Welcome to WixCode. Glad to have you aboard.

You can use text input fields, dropdown menus, and other user input elements to collect your search criteria. Then, using the information in your search criteria, set a filter on the collection’s dataset which will give you the results you are looking for. Refer to the wix-dataset-setFilter() documentation for a full explanation.

To give you an idea of what you can do, here is a simple example from the setFilter() documentation:

import wixData from 'wix-data';

// ...

$w("#myDataset").setFilter( wixData.filter()
  .startsWith("lastName", "D")
  .ge("age", "21")
);

As you can see in the above example, you can filter just about any way you want - the possibilities are nearly endless.

Good luck,

Yisrael

Hi Yisrael

Thanks for your help! - much appreciated… you guys at Wix are awesome!

Glad to help Ashley - we’re always here for you.

Hi, I’m being a bit ambitious here to attempting this, need some advice on how to code this (never coded javascript before but learning).

Hi antzasia,

Take a look at the Cascading Form code example , it does just what you need. I would suggest opening the example in the editor and playing with it to see how it works.

Since you’re just learning Javascript, I would suggest learning as much as you can from the wide variety of Javascript coding sites available on the web. You’ll find everything from beginner to advance. One good site is Javascript.info . The Wix Code Resources page provides tutorials, examples, and articles on getting the most out of Wix Code. As questions or difficulties arise, come back and visit the forums where you are sure to get great advice from the community and from all of us at Wix.

Have fun,

Yisrael

Hi Yisrael,

Good day.
May I have your attention please?
Could you please look at this —> https://www.wix.com/code/home/forum/questions-answers/field-key-connect-to-the-repeater

Thank you,
Geo

Hi Yisrael, thanks for the tip. Just to clarify, in this example you provided, we don’t need to create a database collection?

The example project merely demonstrates an example scenario. The dropdown options can be from the same collection as the first, from a different one, or even from a set of arrays that are part of your code.

Noted. Thanks Yisrael.

hey! Yisrael.
i am facing a problem just like antzasia mentioned above and i had followed up the cascading form tutorial but unable to solve my issue can u help me?


this is how my webpage looks like. the drop box contains budget field options and searching is done but i want another dropbox for time field the search for a result that contains budget=1000 rs and time <= 2hrs.
code that i m using currently is:-
import wixData from ‘wix-data’;

$w.onReady(function () {
//TODO: write your page related code here…

});
export function searchButton_onClick() {
wixData.query(‘Options’)
.contains(‘budget’, $w(‘#dropdown1’).value)
.find()
.then(res => {
$w(‘#table2’).rows = res.items;
});
}

Hi Dipesh,

You just need to add whatever extra query filters that you need. Something like this:

let budget = $w("#dropdown1").value;
let time = $w("#dropdown2").value;

wixData.query("collection")
  .contains("budget", budget)
  .contains("time", time)
  .find()
  .then( (results) => {
    let items = results.items;  // array of results
    $w('#table2').rows = items; 
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Good luck,

Yisrael

hey , yisrael
i hv done the coding as suggested by you, but didn’t get results as per my requirements.
after selecting budget and time from the dropdowns and clicking the search button there are no results displayed in the table.
please help me asap!!
https://dipeshjn169.wixsite.com/tymscoop

Hi yisrael,

This was perfect for me too! :slight_smile:

TONS of thanks!

What can I put to tell the script that if the drop menu is empty to consider it as “ALL”

Thanks again :slight_smile:

Hi Yisrael!, I’m coding multiple field searches to be displayed at once. I want my users to be able to find their search from a database. Users search for: “Location”, “Age”, " Language" and “Date and Time” for classes. Have been reading wix tutorials and following forums closely which has helped a lot but I still have some errors when running the code. My table isn’t connected to the dataset so I’m defining columns using the API for tables .
Thank you in advance for your help!
This is what I have so far:

import wixData from ‘wix-data’;
// For full API documentation, including code examples, visit Velo API Reference - Wix.com
$w.onReady(function () {
$w(“#table1”).columns = [
{
“id”: “location”, // ID of the column for code purposes
// // The field key in the collection whose data this column displays
“dataPath”: “address”,
“label”: “Address”, // The column header
“width”: 100, // Column width
“visible”: true, // Column visibility
“type”: “string”, // Data type for the column
} ,
{
“id”: “age”,
“dataPath”: “ageRecommendations”,
“label”: “Age Suggested”,
“width”: 100,
“visible”: true,
“type”: “string”,
} ,
{
“id”: “language”,
“dataPath”: “language”,
“label”: “Language”,
“width”: 100,
“visible”: true,
“type”: “string”,
} ,
{
“id”: “dateandtime”,
“dataPath”: “timeDate”,
“label”: “Date & Time”,
“width”: 100,
“visible”: true,
“type”: “string”,
}];
});

//TODO: write your page related code here... 

export function search_click(event, $w) {
//Add your code for this event here:
// Runs a query on the “formulariogrupo” collection
wixData.query(‘formulariogrupo’)
.contains(‘location’, $w(‘#input1’).value)
.find()
.then(res => {
$w(‘#table1’).rows = res.items;
$w(‘#table1’).show();
};
export function dropdown3_click(event, $w) {
//Add your code for this event here:
wixData.query(‘formulariogrupo’)
.contain (‘ageRecommendations’, $w(‘#dropdown3’).value)
.find()
.then(res => {
$w(‘#table1’).rows = res.items;
$w(‘#table1’).show();
}

export function dropdown2_click(event, $w) {
//Add your code for this event here:
wixData.query(‘formulariogrupo’)
.contain (‘language’, $w(‘#dropdown2’).value)
.find()
.then(res => {
$w(‘#table1’).rows = res.items;
$w(‘#table1’).show();
}

export function datePicker1_click(event, $w) {
//Add your code for this event here:
.contain (‘timeDate’, $w(‘#datePicker1’).value)
.find()
.then(res => {
$w(‘#table1’).rows = res.items;
$w(‘#table1’).show();

Hi Yisrael, I have a table with many columns and rows of data populated from my database. I was able to put a search box where people can input any information and it will narrow down display on the table to whatever similar information is available in the table/database. The problem is I can only search a criteria at one time, like I can only search “age” and it displays the information for the all people of that age, then I will have to search another criteria like “location” in same search box and it shows all locations both outside and within the age. I want to use the same search box to narrow down my search on the table without using extra dropdown selections. eg 26 Newyork on my search box then it narrows down to all 26 year olds in newyork
Please explain in details thanks

$w.onReady( function () {
//TODO: write your page related code here…
});

export function filterInput_keyPress(event) {
$w(" #PEOPLEread “).setFilter(wixData.filter()
.contains(“NAME”, $w(” #filterInput “).value)
.or(wixData.filter().contains(“Age”, $w(” #filterInput “).value))
.or(wixData.filter().contains(“Location”, $w(” #filterInput ").value)));
}