I am very new (and getting on years) to coding and am struggling to code a count of filtered dataset and displaying the results on the page. I have written some code which seems to work in filtering a dataset (#dataset13) by a combination of 4 dropdown boxes. The filter is undertaken by clicking on button3. I have also coded a reset which sets the values in the dropdown boxes to “” and loads the complete dataset. I wish to display the number of filtered records in three separate ways
- All the dataset records when the page loads
- The filtered dataset records on clicking button3
- All the dataset records when resetting the dropdown boxes by clicking button5
The code I have written is outlined below and is not working in the following way
- The #text2 box displays “text” when the page loads not the total number of records
- The total number of records is displayed if button3 is clicked with no filter parameters entered
- When I put a filter parameter in any of the dropdown boxes and click button3 then the number of filtered records displayed remains the same eg the total records
- If I click button3 a second time then the filtered number of records is displayed
- The same process happens with the reset button5
I hope you can help as I have spent hours on this trying to resolve it. As I mentioned earlier I am very very new to coding
Thank You
Trevor
import wixData from "wix-data";
$w.onReady(function () {
});
export function button3_click(event) {
//Add your code for this event here:
$w("#dataset13").setFilter(wixData.filter()
.contains("location", $w('#dropdown1').value)
.contains("type", $w('#dropdown2').value)
.contains("year", $w('#dropdown4').value)
.startsWith("distance", $w('#dropdown3').value, )
);
let count = $w("#dataset13").getTotalCount().toString();
$w('#text2').show();
$w('#text2').text = count + " results found";
}
export function button5_click(event) {
//Add your code for this event here:
$w('#dropdown1').value = "";
$w('#dropdown2').value = "";
$w('#dropdown3').value = "";
$w('#dropdown4').value = "";
$w("#dataset13").setFilter(wixData.filter()
);
let count = $w("#dataset13").getTotalCount().toString();
$w('#text2').show();
$w('#text2').text = count + " results found";
}