Question:
Combine Constant Filters with Optional Filters Velo
Product:
Wix Editor
What are you trying to achieve:
I have dropdown filters run by velo code. This overwrites the filters set via dataset settings, whenever a dropdown option is selected. How do I maintain a Boolean filter fixed always?
(I have several DD filters combined, I’ve shown only one below)
import wixData from 'wix-data';
$w.onReady(async function () {
await setupCountriesDropdown();
setupSubjectDropdown();
});
function setupSubjectDropdown() {
$w("#subjectDropdown").onChange(filterAndApply);
}
async function filterAndApply() {
let filter = wixData.filter();
const subject = $w("#subjectDropdown").value;
if (subject) {
filter = filter.ge("subjects", subject);
}
$w("#listingsDataset").setFilter(filter);
}
What have you already tried:
This is follow up to this solution Combine Multiple Filters with Velo
Hi, Gideon_Skarzgard !!
In that case, instead of setting filters in the dataset, use .and()
or .or()
in your code to build the filter conditions. This way, you can keep the filters you always want to apply while adding new conditions. This method ensures that the necessary filters won’t be overwritten.

async function filterAndApply() {
let filter = wixData.filter();
const subject = $w("#subjectDropdown").value;
if (subject) {
const subjectFilter = wixData.filter().ge("subjects", subject);
const anotherFilter = wixData.filter().eq("subjects", "someValue");
filter = subjectFilter.or(anotherFilter);
}
await $w("#listingsDataset").setFilter(filter);
}
Thanks for the response @onemoretime but unfortunately that code didn’t work. It removes too many valid results. I tried different orientations of it too to no avail.
To further clarify, I’ll show more of my code & specifics.
The constant filter is a Boolean one of a different field (‘hide’, false).
I’ll show 3 of my 7 dropdowns. If possible, can the constant filter be included in a more simplified way (rather than having to be repeated for every drop down)?
I appreciate your help!
import wixData from 'wix-data';
$w.onReady(async function () {
await setupCountriesDropdown();
setupSubjectDropdown();
setupLevelDropdown();
setupCapacityDropdown();
});
function setupSubjectDropdown() {
$w("#subjectDropdown").onChange(filterAndApply);
}
function setupLevelDropdown() {
$w("#levelDropdown").onChange(filterAndApply);
}
function setupCapacityDropdown() {
$w("#capacityDropdown").onChange(filterAndApply);
}
async function filterAndApply() {
let filter = wixData.filter();
const subject = $w("#subjectDropdown").value;
if (subject) {
filter = filter.ge("subjects", subject);
}
const level = $w("#levelDropdown").value;
if (level) {
filter = filter.ge("level", level);
}
const capacity = $w("#capacityDropdown").value;
if (capacity) {
filter = filter.ge("capacity", capacity);
}
$w("#listingsDataset").setFilter(filter);
}
If the dataset’s item retrieval limit is too low, the results may not be displayed correctly. In this case, try increasing the dataset’s retrieval limit. How many items are currently set to be retrieved? Is it 12 or 50? If the number of items is very large, it may be better to consider paging the results rather than retrieving all items at once. 
Also, filters are generally overwritten each time. Therefore, if you want to set fixed filter conditions, you will need to explicitly set them in your code each time. Mixing filter settings between the editor and the code can lead to unintended behavior, so I recommend unifying the approach to filter settings, either through the editor or the code. If you’re comfortable working with code, there’s no need to rely on the editor’s UI to set filters. 
Alternatively, you could stop using the dataset and use the wix-data API instead.
https://dev.wix.com/docs/velo/api-reference/wix-data/query
Hi yes, the results retrieval limit isn’t the issue as it’s set to 100, and the valid results are less than 20, which load when the filter is not applied.
Yes I don’t use the editor, and meant how it can be simplified in code. I’m so close to the solution though, and a very few lines of code is all that’s missing/misarranged. But as a noncoder I can’t seem to solve it, despite hours of scouring all available forums and YouTube videos on the topic. This little fix would be a huge relief🙏