I’m using a button to reload my page with a URL query param called ‘source’. The param is used to populate my dataset filter so that it only shows records from that ‘source’. When I click the search button, the wixlocation To( ) works and I can see my param assigned properly. The problem is that the internal page that loads isn’t refreshing (since its the same page just with an updated source param) and hence, I’m still getting the previous search results. When I manually refresh the page, it shows the updated filter results. So how do I get the page to refresh right after the To() is executed?
Here’s the code:
import wixLocation from 'wix-location';
import {local} from 'wix-storage';
import wixData from 'wix-data';
let source = "";
let count = 0;
$w.onReady(function () {
//TODO: write your page related code here...
let nlcolor = local.getItem("nlcolor");
let navlink = $w('#text35').html;
$w('#text35').html= navlink.replace("white", nlcolor);
if (typeof wixLocation.query.source !== 'undefined'){
source = wixLocation.query.source;
console.log("source is populated with: [" + source + "]");
}
if (source===""){
//do nothing
console.log("source is empty");
$w("#dynamicDataset").onReady( () => {
$w('#dynamicDataset').setFilter( wixData.filter() );
$w("#listRepeater").expand();
$w("#listRepeater").show();
} );
$w('#group6').show();
$w('#group7').show();
$w('#group8').show();
}else{
$w('#group6').hide();
$w('#group7').hide();
$w('#group8').hide();
console.log("source = " + source);
$w('#sourceaccount').value = source;
$w("#dynamicDataset").onReady( () => {
$w('#dynamicDataset').setFilter( wixData.filter()
//.eq("Username", "honey_morgan09")
.startsWith('username', source)
)
.then( () => {
console.log("Dataset is now filtered and visible set to: " + $w("#listRepeater").isVisible);
$w("#listRepeater").forEachItem( ($item, itemData, index) => {
count = count + 1;
} );
console.log("count total = " + count);
$w("#listRepeater").expand();
$w("#listRepeater").show();
//$w("#dynamicDataset").refresh();
} )
.catch( (err) => {
console.log(err);
} );
} );
}
});
export function search_click(event) {
source = $w('#sourceaccount').value;
wixLocation.to('/moments?source=' + source);
}