Suppose I have two datasets A and B and their Data eg. List (Field Name). Kindly see below images.
Kindly help me to eliminate/do not display/filter option in DATA_B dropdown comparing similar option through code. Any help in regard will be helpful. Thanks in advance. : )
Allow me to show another way of doing this, assuming that your dropdowns are manually connected instead of coded.
//Function that filters repeated items from dropdowns const filter = (list, listToFilter) => { return listToFilter.filter(({ label }) => !list.some(item => item.label === label)) } $w.onReady(async () => { //Wait for the dataset A to be ready $w('#datasetA').onReady(() => { //Wait for the dataset B to be ready $w('#datasetB').onReady(() => { //Get the dropdown values const dd1 = $w('#dropdown1').options const dd2 = $w('#dropdown2').options //Filter the values const filteredDD = filter(dd1, dd2) //Feed them to the dropdown that needs filter $w('#dropdown2').options = filteredDD }) }) })
Best regards.
Try something like:
import wixData from 'wix-data'; let dataset1Lists; let isDataset2Ready = false; $w.onReady(() => { $w('#dataset1').onReady(() => { $w('#dataset1').getItems(0, 1000).then(r => { dataset1Lists = r.items.map(e => e.list); filterDataset2(); }); }); $w('#dataset2').onReady(() => { isDataset2Ready = true; filterDataset2(); }); }); function filterDataset2() { if (dataset1Lists && isDataset2Ready) { if (dataset1Lists.length > 0) { let filter = wixData.filter(); dataset1Lists.forEach(e => filter = filter.ne('list', e)); $w('#dataset2').setFilter(filter); } } }