Hi, I’ve two dropdown which I use to filter the dataset. Following code I use to filter the dataset & working fine.
filter = filter.eq("_owner", wixUsers.currentUser.id).and(filter.contains("expenseFor", filter1)).and(filter.contains("type", filter2))
I’ve another result which I stored in array with name “arryo”. Object is shown below:
0: {...}
type: "Debit"
principal: 15000
days: 1
interest: -4.75
expfo: "Ration"
1: {...}
type: "Credit"
principal: 3000
days: 1
interest: 1
expfo: "pesticides"
Now, I want to filter this array using dropdown1 → expfo & dropdown 2 → type
I’ve tried with four combination of two dropdown array filter is working fine. But in case I increase the dropdown then it’s hard to write each & every case. Please help me.
First, I tried to filter using both dropdowns condition but failed because intially dropdown value is “” which make array empty too. So, I try something this again but this is entering only in if loop. Besides this, I’ve tried not of methods but failed.
let doo = arryo.filter(function (currentElement) {
if ($w('#dropdown1').value !== "" || $w('#dropdown1').value !== undefined || $w('#dropdown1').value !== null) {
console.log("Entered in IF");
return currentElement.expfo === $w('#dropdown1').value;
}
else{
console.log("Entered in Else");
return currentElement;
}
});
Approach: - Now, my approach is to filter the array with dropdown1. If dropdown selected then items will be filtered and then check this with dropdown2 using filter. If any of the dropdown value is not available then return the entire array as it is.
I’m unable to implement my approach. If you help me with this please reply. Also, if you’ve better code then please let me know.
Thank you