Hello and thanks for your answer!
I know that you can have an or/and etc in a filter, but however this is only if you know from the start which filters you will use.
If for example we have 5 filter options for the client(color-size-price etc.) but we do not know which filters he will use having or/ands in a single filters will not solve this…because we do not know which he will use.
Hi Maria. I just made a 8 filter situation on a repeater, 4 droplists, 4 checkboxes, and some others this weekend. This is all done using standard wixData.filter(). So you get e.g. wixData.filter().contains().hassome() and so on.
Two important things:
make sure the columns for your filters have data, that is the easiest. So instead of ‘’ store ‘undetermined’ or what ever. This way when you do e.g. ‘contains(column, ‘’)’ it will be found for it has data in it.
you can use an if condition within the wixData.filter(). this will work in situaions where you need a string to be passed. You can do that with e.g. wixData.filter().contains(column, (‘a === b’) ? true_value : false_value)
It does require some puzzel to get it working the first time. I would understand that might go far for some, so if you can pass some more info on your element ids, values of the elements I can type something more readable for you situation.
When I’ve time I’ll make a ‘howto’ for this, but that’s not done this month.
Hey and thanks for your comment!
At this moment i have done it like that, but i just posted here to see if there is a simpler and more efficient way to do it…
Something like
//Filter One
$w("#DatasetToBeFiltered").setFilter( wixData.filter()
.startsWith("lastName", "D")
.ge("age", "21")
)
//Filter Two(Would be good for example to have a "AddFilter" in which it will
//just apply the new filter to the old one.
$w("#DatasetToBeFiltered").AddFilter( wixData.filter()
.startsWith("lastName", "A") //other conditions
.ge("age", "22") //other conditions,but also keep the last ones.
)
Ah that I didn’t read. I make my query dynamic, but then I didn’t use a dataset then. I use the query API where there is more control. That ‘addFilter’ would be a nice enhancement
You can add filters to your current filter like this:
filter = filter.eq();
This enables you to be very flexible:
// init the filter
var filter = wixData.filter()
.contains(xx, yy)
.or();
// add another condition and keep old filters
filter = filter.ne(xx, yy);
// conditional filter
if (xyz) {
filter = filter.eq(xx, yy)
}
// finally, we set the filter
$w("#dataset1").setFilter(filter);
I am having trouble with this as well. I’ve managed to get the first 2 filters to work (a text and dropdown) but when I add a 3rd filter it isn’t working. My js knowledge is more find and replace than write from scratch so any detailed help is MUCH appreciated.
The 3rd filter “Price” is the one not working.
Here is my code:
import wixData from "wix-data";
$w.onReady(() => {
loadBedrooms();
});
let lastFilterTitle;
let lastFilterBedrooms;
let lastFilterPrice;
let debounceTimer;
export function iTitle_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w('#iTitle').value, lastFilterBedrooms, lastFilterPrice);
}, 200);
}
export function dropdownBedrooms_change(event, $w) {
filter(lastFilterTitle, $w('#dropdownBedrooms').value);
}
export function dropdownGuests_change(event, $w) {
filter(lastFilterBedrooms, $w('#priceRang').value);
}
function filter(title, bedrooms, price) {
if (lastFilterTitle !== title || lastFilterBedrooms !== bedrooms){
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains('propertyName', title);
if (bedrooms)
newFilter = newFilter.ge('ofRooms', bedrooms);
if (price)
newFilter = newFilter.le('priceLow', price);
$w('#dataset1').setFilter(newFilter);
lastFilterTitle = title;
lastFilterBedrooms = bedrooms;
lastFilterPrice = price;
}
}
function loadBedrooms () {
wixData.query('ofRooms')
.find()
.then(res => {
let options = [{"value": '', "label": 'Any'}];
options.push(...res.items.map(bedrooms => {
return {"value": bedrooms.title, "label": bedrooms.title};
}));
$w('#dropdownBedrooms').options = options;
});
}
Hello please can you help me? I need your assistance i have set a filter using multiple checkboxes that displays the result in a table. But the prblemis that mobile view of the table is not propper i have tried every thing i know in vain i thing my code is not good that’s the reason. Can you olease help me to figure it out ?