I have a “search” page with a repeater control linked to a dataset. The dataset is linked to a database collection with all rows as default i.e. there are no filters.
There is a search field (#cboCategory & #txtSearch) and a search button on all pages. Search button calls the below function:
export function btnSearch_click(event, $w) {
if (wixLocation.path==“search”) {
Search($w(“#cboCategory”).value,$w(“#txtSearch”).value.trim(),$w(“#repeater1”));}
else {
wixLocation.to(“/search”);}
}
Below code is executed on the w.onReady() event of the Search page:
$w.onReady(function () {
//TODO: write your page related code here…
Search($w(“#cboCategory”).value,$w(“#txtSearch”).value.trim(),$w(“#repeater1”));
});
The Search() function is a javcscript code as per below:
export function Search(selectedCategory,selectedSearch,SearchRepeaterData) {
const keywords = selectedSearch.split(‘;’) ;
const allQueries = keywords.map(keyword => queryByKeyword(selectedCategory,keyword))
// join the different queries into one query using OR
const joinedQuery = joinQueriesWithOr(allQueries)
joinedQuery.find()
.then( (results) => {
SearchRepeaterData.data = results.items;
} )
.catch( (err) => {
let errorMsg = err;
} );
}
When the Search button it clicked it is executing the dataset linked to the repeater control, as a result the search criteria is not being executed on the first time load of the search form.
I would like it to instead execute the $w.onReady(function on the Search page. Is this possible to bypass the default query on the Dataset?