Hello! Sorry for my English, since I translate my language through an online translator. Thank you! I need help… I have a table, I want it to show data from the database based on two drop-down lists for filtering. There is a code that I found in the forum space. I substituted my data, but it does not work for me. Please see what I’m doing wrong. Thank you in advance!!!
import wixData from “wix-data”;
$w.onReady(function () {
// Run a query that returns all the items in the collection
wixData.query(“Applicants”)
// Get the max possible results from the query
.limit(1000)
.ascending(“title”)
.find()
.then(results => {
// Call the function that creates a list of unique job Vacancy
const uniquejobVacancy = getUniquejobVacancy(results.items);
// Call the function that builds the options list from the unique job Vacancy
$w(“#dropdown1”).options = buildOptions(uniquejobVacancy);
});
});
// Build an array from the “job Vacancy” field only for each item in the collection and then removes the duplicates
function getUniquejobVacancy(items) {
// Use the map method to create the job VacancyOnly object containing all the last Names from the query results
const jobVacancyOnly = items.map(item => item.title);
// Return an array with a list of unique job Vacancy
return […new Set(jobVacancyOnly)];
}
// Build an array from the “extras Job Vacancy” field only for each item in the collection and then removes the duplicates
function getUniqueextrasJobVacancy(items) {
// Use the map method to create the extras Job VacancyOnly object containing all the job Vacancy from the query results
const extrasJobVacancyOnly = items.map(item => item.extrasJobVacancy);
// Return an array with a list of unique first Names
return […new Set(extrasJobVacancyOnly)];
}
// Creates an array of objects in the form {label: “label”, value: “value”} from the array of titles
function buildOptions(uniqueListLast) {
return uniqueListLast.map(currLast => {
// Use the map method to build the options list in the format {label:uniquejobVacancy, value: uniquejobVacancy}
return {
label: currLast,
value: currLast
};
});
}
//2. See at which event a member is registered to:
export function dropdown1_change(event) {
$w(“#table1”).hide();
//First Name to be automatically filled-in depending on job Vacancy selected
let jobVacancy = event.target.value;
$w(‘#dataset1’).setFilter(wixData.filter()
.eq(‘title’, jobVacancy)
);
wixData.query(“Applicants”)
// Get the max possible results from the query
.limit(1000)
.eq(“title”, jobVacancy)
.ascending(“extrasJobVacancy”)
.find()
.then(results => {
// Call the function that creates a list of unique extras Job Vacancy
const uniqueextrasJobVacancy = getUniqueextrasJobVacancy(results.items);
// Call the function that builds the options list from the unique extras Job Vacancy
$w("#dropdown2").options = buildOptions(uniqueextrasJobVacancy);
});
}
export function dropdown2_change() {
let extrasJobVacancy = $w(‘#dropdown2’).value;
let jobVacancy = $w(“#dropdown1”).value;
//Once extras Job Vacancy is selected, table with all events appear
$w('#dataset1').setFilter(wixData.filter()
.eq('extrasJobVacancy', extrasJobVacancy)
.eq('title', jobVacancy)
);
$w("#table1").show();
}
I took this code from here : https://www.wix.com/code/home/forum/advanced-tips-tricks/remove-duplicates-from-connected-dropdown-options