Hello,
On a test website for the moment I have a page where a table displays the data of a little database with ten companies for example and for the dropdown by list two another “databases”, for the city and the activity…
I was inspired by this tutorial:
https://www.wix.com/code/home/forum/wix-tips-and-updates/how-to-create-a-search-for-your-database
That works well for the list.
a search by keyword, it’s ok.
I have a search field by activity, it works too.
But the third field, search by city, doesn’t work :
I see that the research is done by activity but I do not know why.
I do not know how to code correctly …
-
import wixData from “wix-data”;
-
/* - Ok - field search by keyword with timing */
-
export function formBusiness_keyPress(event, $w) {
-
if (debounceTimer) {
-
clearTimeout(debounceTimer);
-
debounceTimer = undefined;
-
}
-
debounceTimer = setTimeout(() => {
-
filter($w(‘#formBusiness’).value, lastFilterCompagnyName);
-
}, 500);
-
}
-
/* - Ok - */
-
$w.onReady(() => {
-
loadListCity();loadListActivity();
-
});
-
let lastFilterCompanyName; /* for the search by keywords*/
-
let lastFilterActivity; /Activity = field in the database for all activities : ListActivity/*/
-
let lastFilterActivity2; /Activity2 = field in the company database : ListCompany/
-
let lastFilterCity; /City = field in the database for all the city : ListCity/
-
let lastFilterCity2; /field in the company database/
-
let debounceTimer;
-
/* */
-
export function formActivity_change(event, $w) {
-
filter(lastFilterActivity, $w(‘#formActivity’).value);
-
}
-
export function formCity_change(event, $w) {
-
filter(lastFilterCity, $w(‘#formCity’).value);
-
}
-
/* -Ok - for the dropdown list with city*/
-
function loadListCity() {
-
wixData.query(‘ListCity’)
-
.find()
-
.then(res => {
-
let options = [{"value": '', "label": 'All city'}];
-
options.push(...res.items.map(city2 => {
-
return {"value": city2.city, "label": city2.city};
-
}));
-
$w('#formCity').options = options;
-
});
-
}
-
/* -Ok - for the dropdown list with Activity*/
-
function loadListActivity() {
-
wixData.query(‘Activity’)
-
.find()
-
.then(res => {
-
let options = [{"value": '', "label": 'Tous activitys'}];
-
options.push(...res.items.map(activity2 => {
-
return {"value": activity2.activity, "label": activity2.activity};
-
}));
-
$w('#formActivity').options = options;
-
});
-
}
-
/* the filters… */
-
function filter(companyName, activity, activity2, city, city2) {
-
if (lastFilterCompagnyName !== compagnyName || lastFilterActivity !== activity || lastFilterActivity2 !== activity2 || lastFilterCity !== city || lastFilterCity2 !== city2)
-
{
-
let newFilter = wixData.filter();
-
/* - Ok - search by keyword */
-
if (companyName)
-
newFilter = newFilter.contains('compagnyName', compagnyName)
-
/* - Ok - dropdown list search by activity */
-
if (activity2)
-
newFilter = newFilter.contains('activity2', activity2);
-
/* - Not work - dropdown list search by city...*/
-
if (city2)
-
newFilter = newFilter.contains('city2', city2);
-
/* #ListCompany name of the connexion between the database and the page*/
-
$w('#ListCompany').setFilter(newFilter);
-
lastFilterCompanyName = companyName;
-
lastFilterActivity = activity;
-
lastFilterActivity2 = activity2;
-
lastFilterCity = city;
-
lastFilterCity2 = city2;
-
}
-
}
Could you give me some hints please?
thank you
Have a goo day
Florent