Searchbox that can scans in different column in mycollection

Hey, I was wondering does someone know a way to get the “.filterset” code to not just check 1 column but all of the column in mycollection, for the .textvalue so that when a user want to look for a specific word all they have to do is use the searchbox…

Then the searchbox will check all of the columns and find the words that contains the input .textvalue

That would help a lot.

Hi,
You can check each column separately by chaining “.contains()” in the setFilter code. For example

$w("#myDataset").setFilter( wixData.filter() 
.contains("lastName", "Da") 
.contains("firstName", "Da") 
);

Good luck :slight_smile:

Sorry but the code is searching the keyword in both columns. I’m trying to do something like if the code can’t find the keyword in column 1 then it will search in column 2 for the keyword. Does this make sense?

You can use query to check whether the keyword exists in a column, if it doesn’t you can check another column and so on…
After that, you can use the setFilter.
Check out the following article:

I try doing that, but for some reason the code says their no problem but when I preview it dosen’t work…

Hi arthosmaciel,

How about the following approach:

import wixData from 'wix-data';

const columnNames = ['column1', 'column2', 'column3'];

function findResults(columnName, searchString) {
    wixData.query('collectionName').contains(columnName, searchString).find().then(result => {
        if(result.items.length > 0) {
            //items found, do something here
        }
        else {
            const indexOfCurrentColumn = columnNames.indexOf(columnName);
            if (indexOfCurrentColumn === columnNames.length -1) {
                //finished all columns, no results to show
            } else {
                const nextColumn = columnNames[indexOfCurrentColumn + 1];
                findResults(nextColumn, searchString);
            }
        }
    });
}

then, lets say you have a button that searches upon input text, here’s the onClick:

export function button1_click(event) {
	const stringToSearch = $w('#input1').text;
	findResults(columnNames[0], stringToSearch);
}

You can of course use the callback in ‘$w.isReady()’ to automatically create the array with the names of the columns.

Hope this helps,

Liran.

Thanks for the code but how do I connect it to the table? Here is the information I’m trying to connect to the table chart & search box:

  • Collection Name : ApplicationForm

  • Column Names : applicationStatus, Revisor, fullName, email

  • Table Chart : #table1

  • Search Box : #textInput1

  • Search Button : #searchButton

const columnNames = ['applicationStatus', 'Revisor', 'fullName', 'email'];

function findResults(columnName, searchString) {
	wixData.query('ApplicationForm').contains(columnName, searchString).find().then(result => {
		if (result.items.length > 0) {
			//items found, do something here
		} else {
			const indexOfCurrentColumn = columnNames.indexOf(columnName);
			if (indexOfCurrentColumn === columnNames.length - 1) {
				//finished all columns, no results to show
			} else {
				const nextColumn = columnNames[indexOfCurrentColumn + 1];
				findResults(nextColumn, searchString);
			}
		}
	});
}

export function searchButton_onClick() {
	const stringToSearch = $w('#textInput1').value;
	findResults(columnNames[0], stringToSearch);
}

Hi,
Since this is a bit complex, you can use code to update your fields, instead of connecting it.
I assume each applicationStatus, Revisor, fullName, email have text boxes.
Try doing something like that at the line that gets the result:

if (result.items.length > 0) {
    //items found, do something here 
    const firstItem = result.items[0];
    $w('#applicationStatusText').text = firstItem.applicationStatus;
    $w('#RevisorText').text = firstItem.Revisor;
    //More text updates here...
 }

Liran.

How do I connect the code from above to the wix table: #table1 (the default one from the add section)