Hello,
So I have a fully working search bar and filter drop-down but I would love to set it so It keeps the filter if you search or you can filter search results. Any way to do this without rewriting the whole code?
Current Code:
import wixData from ‘wix-data’;
var count=0;
//count of database entries on opening site
$w.onReady( function () {
$w(‘#dataset1’).onReady(() => {
let countStart = $w(‘#dataset1’).getTotalCount();
countStart = $w(‘#resultsTotal’).text=countStart.toString().concat(’ Results Found’);
})
})
//end
//count after search and reset code
function updateCount(){
count = $w(‘#repeater1’).data.length;
count = $w(‘#dataset1’).getTotalCount();
$w(‘#resultsTotal’).text=count.toString().concat(’ Results Found’);
}
//end
//searching the database code
function searchDatabase(){
let searchValue = $w(“#databaseSearch”).value;
$w(“#dataset1”).setFilter(wixData.filter().contains(‘title’, searchValue).
or(wixData.filter().contains(‘doi’, searchValue)).
or(wixData.filter().contains(‘authors’, searchValue)).
or(wixData.filter().contains(‘publicationYear’, searchValue)).
or(wixData.filter().contains(‘keyword’, searchValue)).
or(wixData.filter().contains(‘publishedIn’, searchValue)))
.then(updateCount);
}
//end
//Search button code
export function searchButton_click(event, $w) {
searchDatabase()
}
//end
//reset search button code
export function resetButton_click(event, $w) {
$w(“#databaseSearch”).value = undefined;
// $w(“#dropdown1”).selectedIndex = 0;
$w(“#dataset1”).setFilter(wixData.filter()).then(updateCount);
}
//end
//type drop down code
export function dropdown1_change(event) {
let filterType = $w(‘#dropdown1’).value;
if (filterType === “All”){
$w(‘#dataset1’).setFilter(wixData.filter()).then(updateCount);
} else {
$w(‘#dataset1’).setFilter(wixData.filter().contains(“type”, filterType)).then(updateCount);
}}
//end