Repeater with Search Filter

Page in question: https://jds-cvoa.wixsite.com/cvoa/CVOA-Registry

I am trying to implement a filter to fix a problem with the Get Next items in the Dataset.

If I access this page without any search contents, it properly shows the first 10 items, then the Get Next Ten button (linked to database Next Items). It all works as expected.

However, If I search on Color for example and select “Blue” as the value, It retrieves all the Blue items, But the Get Next Ten button is not greyed out. So, if I click that it goes to the database and retrieves the First 10 records which are NOT blue"

Searching this forum I thought I needed to implement a filter in the search statements. Here is my code:

case “3”: $w(“#dynamicDataset”).setFilter(wixData.filter().eq(‘exterior_color’, $w(‘searchColor’).value))
wixData.query(‘CVOA-Registry’).contains(‘exterior_color’, $w(‘#searchColor’).value)
.find()
.then(res => {
$w(‘#repeater1’).data = res.items;
// console.log("SEARCHED FOR COLOR: ", $w(‘#searchColor’).value)
});
break;

case “2”: $w(“#dynamicDataset”).setFilter(wixData.filter().eq(‘year’, $w(‘searchYear’).value))
(wixData.query(‘CVOA-Registry’).eq(‘year’, $w(‘#searchYear’).value))
//.limit(10)
.find()
.then(res => {
$w(‘#repeater1’).data = res.items;
// console.log("SEARCHED FOR YEAR: ", $w(‘#searchYear’).value)
});
break;

case “1”: $w(“#dynamicDataset”).setFilter(wixData.filter().eq(‘dash’, $w(‘searchDash’).value))
(wixData.query(‘CVOA-Registry’).eq(‘dash’, $w(‘#searchDash’).value))
.find()
.then(res => {
$w(‘#repeater1’).data = res.items;
// console.log("SEARCHED FOR DASH: ", $w(‘#searchDash’).value)
});
break;

default:
break;
}

This does not work.

Thanks
JD

As a temporary work around:

  1. removed the filter from each switch case,
  2. added more/next button.hide when inside the switch statement.
  3. Added a Reset button at top of page along with an onclick event to button.show.

Solves problem with the Color and The Dash#. But there are over 1000 cars in each Year category so hidden more will not allow viewing all of each year. Need Filter on the year and no HIDE more button for that switchase case.

HERE IS REVISED CODE:
//CURRENT REGISTRY SEARCH

export function searchButton_click(event, $w) {

let search = “1”
let i = 0;
if ($w(‘#searchColor’).value !== ‘Color’) search = “3”;
if ($w(‘#searchYear’).value !== ‘Year’) search = “2”;
if ($w(‘#searchDash’).value !== ’ Dash#') search = “1”;

console.log(“SWITCH VALUE:”, search);
switch (search) {

case “3”: wixData.query(‘CVOA-Registry’).contains(‘exterior_color’, $w(‘#searchColor’).value)
.limit(60)
.find()
.then(res => {
$w(‘#repeater1’).data = res.items;
$w(“#moreButton”).hide();
});
break;

case “2”: (wixData.query(‘CVOA-Registry’).eq(‘year’, $w(‘#searchYear’).value))
.limit(25)
.find()
.then(res => {
$w(‘#repeater1’).data = res.items;
$w(“#moreButton”).hide();
});
break;

case “1”: (wixData.query(‘CVOA-Registry’).eq(‘dash’, $w(‘#searchDash’).value))
.limit(10)
.find()
.then(res => {
$w(‘#repeater1’).data = res.items;
$w(“#moreButton”).hide();
});
break;

default:
break;
}

$w(‘#searchDash’).value = " Dash#"
$w(‘#searchYear’).value = “Year”
$w(‘#searchColor’).value = “Color”
}

export function searchDash_click(event, $w) {
//Add your code for this event here:
$w(‘#searchDash’).value = “”
}

export function reset_click(event, $w) {
$w(“#moreButton”).show();
//Add your code for this event here:
}

Hey,
Have you managed to resolve it? If not, can you please clarify what was the issue?

Thanks,
Tal.

Thanks Tal,
I have somewhat resolved the problem by redesigning how it works… I overrode the default limit set in the database with a limit(xx) and hides the MORE button for the searches. I put a RESET search button which shows the MORE button and in order for it to start over with the items in the database I added…

export function reset_click(event, $w) {
wixData.query(‘CVOA-Registry’)
.between(‘dash’, ‘0000’, ‘0020’)
.limit(12)
.find()
.then(res => {
$w(‘#repeater1’).data = res.items;
} )
$w(“#moreButton”).show();
}
Still have a slight problem in that the FIRST item is '0001". The results from the database skip the first record for some reason.