Count number of filtered items

Hi,
I have this code working, to filter a database and then only show on a list the filtered items.
Can someone help me adding code that will also count the number of filtered items and display the count into an input box.
I already do this to count the total number of items into my database and post it in an input box

Thank you any help will be very much appreciated
Pierre
ibmretraitesqc

Here is my code for that filter option:
export function input3_keyPress(event, $w) {
if (debounceTimer) {1// clearTimeout(debounceTimer);

debounceTimer = undefined;
}
debounceTimer = setTimeout (() => {
filter1($w(‘#input3’).value);
}, 200);
}
console.log (filter)
let lastFilterTitle2;
function filter1(title) {
if (lastFilterTitle2 !== title) {
$w(‘#dataset1’).setFilter( wixData.filter().contains(‘nomComplet’,title));
lastFilterTitle2 = title;
$w(“#anchor1”).scrollTo()
$w(“#dropdown1”).value = “”
$w(“#input2”).value = “”
}

//code.........code...
$w('#dataset1').setFilter( wixData.filter().contains('nomComplet',title))
.then((res) => {
    let count = $w("#dataset1").getTotalCount();
    $w("#text1").text = count.toString();
})
//the rest of the code...

Hi, did apply your suggestion and it partially works. I get my filter input from an input box. If I type too fast, randomly I get 0 as a count. Is there a way to fix this?
Works 9 times out of 10.

Thank you for your help

Here is my code:

export function input2_keyPress(event, $w) {
if (debounceTimer) {1//clearTimeout(debounceTimer);

debounceTimer = undefined;
}
debounceTimer = setTimeout (() => {
filter($w(‘#input2’).value);
}, 200);
}
console.log (filter)
let lastFilterTitle;
function filter(title) {
if (lastFilterTitle !== title) {
$w(‘#dataset1’).setFilter( wixData.filter()
.startsWith(‘villeActuelle’,title)
.contains(“autorisation”, “ok”))
.then((res) => {
let count = $w(“#dataset1”).getTotalCount();
$w(“#input1”).value = count;
});

lastFilterTitle = title;
//count = $w(“#dataset1”).getTotalCount();
//$w(‘#input1’).value = count;
$w(“#anchor1”).scrollTo()
$w(“#input3”).value = “”
$w(“#dropdown1”).value = “”
}}

@ibmretraitesqc I don’t know, but I also don’t understand the beginning of your code:

 if (debounceTimer) {1//clearTimeout(debounceTimer); 

I highlighted in red the part I just don’t understand. Why do you have there number 1? Why did you change the clearTimout to an un-functioning notation?

@jonatandor35 Hi, I am sorry. This was a mistake (typo) on my part. I have removed this and increased the timeout value to 800 and it seems to work fine now.

Thank you for your help

Pierre