Hi all - I have successfully added the 'search a database' code and elements to my page and am now happy with that.
However, in the datasets settings, (formerly) I had a filter to make sure that all data shown contains 'employers' in a specific field and not items for 'candidates' etc. Currently, with the new code implemented, when I select a specific topic from the dropdown menu, it will only show employers specific items. But, when returning to 'all topics', it now shows all items, including the employers and candidates.
import wixData from "wix-data";
$w.onReady(() => {
loadtopic();
loadtype();
});
let lastFilterTitle;
let lastFiltertopic;
let lastFiltertype;
let debounceTimer;
export function iTitle_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w('#iTitle').value, lastFiltertopic, lastFiltertype);
}, 500);
}
export function itopic_change(event, $w) {
filter(lastFilterTitle, $w('#itopic').value, lastFiltertype);
}
export function itype_change(event, $w) {
filter(lastFilterTitle, lastFiltertopic, $w('#itype').value);
}
function filter(title, topic, type) {
if (lastFilterTitle !== title || lastFiltertopic !== topic || lastFiltertype!== type) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains('title', title);
if (topic)
newFilter = newFilter.contains('topic', topic);
if (type)
newFilter = newFilter.contains('type', type);
$w('#archiveDataset').setFilter(newFilter);
lastFilterTitle = title;
lastFiltertopic = topic;
lastFiltertype = type;
}
}
function loadtopic() {
wixData.query('topic')
.find()
.then(res => {
let options = [{"value": '', "label": 'All topics'}];
options.push(...res.items.map(topic => {
return {"value": topic.title, "label": topic.title};
}));
$w('#itopic').options = options;
});
}
function loadtype() {
wixData.query('type')
.find()
.then(res => {
let options = [{"value": '', "label": 'All types'}];
options.push(...res.items.map(type => {
return {"value": type.title, "label": type.title};
}));
$w('#itype').options = options;
});
}