I am trying to fill a dropdown list from a collection. This collection has a field (named “ViewOnly”) of type Boolean. I want only the records that have a value of true to be returned by the query. If I comment out the filtering code (i.e. .eq"viewOnly"…) the query successfully returns all records (not what I want) and the dropdown list is successfully populated. If I introduce the filtering code I get no results returned.
I have tried 3 variations on the filtering code:
a) my initial attempt:
wixData.query(“SubmissionStatus”).ascending(“status”)
.eq(“viewOnly”, true )
b) an attempt as a result of a search of previous posts in this forum:
wixData.query(“SubmissionStatus”).ascending(“status”)
.eq(“viewOnly”, Boolean( true ))
c) a final ridiculous and desperate attempt of my own where I compare to a literal:
wixData.query(“SubmissionStatus”).ascending(“status”)
.eq(“viewOnly”, " true" )
Any suggestions would be very appreciated (especially any that work!) Thank you very much.
In my original post I forgot to mention something that might be helpful: I also tried the filtering code such that I am filtering on a text field in the same collection. This is NOT what I want to do, but I simply did this to check that the code is otherwise working. So this code was:
This code worked and successfully returned a filtered set of records from the collection, which then populated the dropdown list. However I do not want to actually filter on this text field, I simply did it to confirm my code was otherwise working. I need to filter on the Boolean field “ViewOnly” as I originally posted and this is what I am struggling to do. Thanks.
c) A final ridiculous and desperate attempt of my own where I compare to a literal:
wixData.query("SubmissionStatus")
.eq("viewOnly", "true") //<--- This can work, but on string-fields only!!!
.ascending("status")
.find()
.then(()=>{ ... });
How to Combine Fixed Filters with Optional Filters?
Hi, I found this thread close to solving my issue. My case varies as follows;
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? This constant filter is of a different field (‘hide’, false).
I’ll show 3 of my 7 dropdowns.
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);
}