Hello,
here how the code will look like with the count added:
import wixData from "wix-data";
$w.onReady(() => {
wixData.query('Category')
.find()
.then(res => {
let options = [{"value": '', 'label': 'All Tours'}];
options.push(...res.items.map(category => {
return {'value': category.title, 'label': category.title}
}));
$w('#iTours').options = options;
})
});
let lastFilterTitle;
let lastFilterCategory;
let count; //declaring the variable to use it after
let debounceTimer;
export function iTitle_keyPress(event, $w) {
if(debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w('#iTitle').value, lastFilterCategory);
}, 200);
}
function filter(title, category) {
if (lastFilterTitle !== title || lastFilterCategory !== category) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains('title', title);
if (category)
newFilter = newFilter.eq('category', category);
$w('#dataset1').setFilter(newFilter);
lastFilterTitle = title;
lastFilterCategory = category;
count = $w("#dataset1").getTotalCount(); // setting the count value
}
}
so now you have a variable (count) that holds the number of items in after applying the filter.
now if you want to show the count on a text box you will need to :
-
add a text box to show the count value on (let’s say the id is text1)
-
assign the count value to it: $w(‘#text1’).text = count ;
-
this line of code will be located after setting the count value:
count = $w("#dataset1").getTotalCount();
$w('#text1').text = count;
good luck!
Massa